FunctorCore test_pyconf.py: Delay LHCb stack imports to when tests are actually run
Avoids problems during build by not attempting to import modules before they are installed, e.g.
[270>22>9/300] Collecting pytest tests for FunctorCore:FunctorCore.pytest.python
FAILED: Phys/FunctorCore/CMakeFiles/pytest-prefetch-FunctorCore-FunctorCore.pytest.python /usera/jonesc/LHCb/stack/Master/Rec/build.x86_64_v3-el9-gcc13-opt/Phys/FunctorCore/CMakeFiles/pytest-prefetch-FunctorCore-FunctorCore.pytest.python
cd /usera/jonesc/LHCb/stack/Master/Rec/build.x86_64_v3-el9-gcc13-opt/Phys/FunctorCore && /cvmfs/lhcb.cern.ch/lib/var/lib/LbEnv/3297/stable/linux-64/bin/cmake -DPREFECTH_PYTEST_TESTS=TRUE -P /usera/jonesc/LHCb/stack/Master/Rec/build.x86_64_v3-el9-gcc13-opt/Phys/FunctorCore/pytest/collect_FunctorCore.pytest.python.Release.cmake
============================= test session starts ==============================
platform linux -- Python 3.9.12, pytest-7.4.0, pluggy-0.13.1 -- /cvmfs/lhcb.cern.ch/lib/lcg/releases/Python/3.9.12-9a1bc/x86_64-el9-gcc13-opt/bin/python
cachedir: build.x86_64_v3-el9-gcc13-opt/Phys/FunctorCore/pytest_cache
CTEST_FULL_OUTPUT
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usera/jonesc/LHCb/stack/Master/Rec/Phys/FunctorCore/.hypothesis/examples')
rootdir: /usera/jonesc/LHCb/stack/Master/Rec
plugins: GaudiTesting-1.0.0, cov-3.0.0, hypothesis-5.3.0
collecting ... collected 21 items / 2 errors
<DoctestModule build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/__init__.py>
<DoctestItem Functors.REQUIRE_CLOSE>
<DoctestItem Functors.RPPVIPCHI2>
<DoctestItem Functors.SHARE_BPV>
<DoctestItem Functors.require_all>
<DoctestItem Functors.require_any>
<Package Functors>
<DoctestModule math.py>
@module Functors
Mathematical functions for use in functor expressions.
<DoctestItem Functors.math.abs>
<DoctestItem Functors.math.arccos>
<DoctestItem Functors.math.exp>
<DoctestItem Functors.math.in_range>
<DoctestItem Functors.math.log>
<DoctestItem Functors.math.pow>
<DoctestItem Functors.math.sign>
<DoctestItem Functors.math.similarity>
<DoctestItem Functors.math.sqrt>
<DoctestItem Functors.math.where>
<Package tests>
<Module test_grammar.py>
<Function test_basic_grammar>
<Function test_array_input>
<Function test_arithmetric>
<Function test_functions>
<Function test_disabled_logical_operators>
<Function test_serialisation>
A BoundFunctor must be seriasable by the pickle module.
<DartMeasurement type="text/string" name="test_arithmetric.source_code"><pre><code class="language-python">def test_arithmetric():
check(30 * GeV &lt; PT)
check(PT &gt; 30 * GeV)
check(PT &gt;= 30 * GeV)
check(PT &lt;= 30 * GeV)
check(PT &lt; 30 * GeV)
check(PT == 30 * GeV)
check(PT != 30 * GeV)
check(PT + ISMUON &gt; 15 * GeV)
</code></pre></DartMeasurement><DartMeasurement type="text/string" name="test_array_input.source_code"><pre><code class="language-python">def test_array_input():
check(VALUE_OR(array('b', [1, 2, 3]))) # vector&lt; signed char &gt;
check(VALUE_OR(array('B', [1, 2, 3]))) # vector&lt; unsigned char &gt;
check(VALUE_OR(array('u', ['a', 'b']))) # vector&lt; wchart_t &gt;
check(VALUE_OR(array('h', [1, 2, 3]))) # vector&lt; signed short &gt;
check(VALUE_OR(array('H', [1, 2, 3]))) # vector&lt; unsigned short &gt;
check(VALUE_OR(array('i', [1, 2, 3]))) # vector&lt; signed int &gt;
check(VALUE_OR(array('I', [1, 2, 3]))) # vector&lt; unsigned int &gt;
check(VALUE_OR(array('l', [1, 2, 3]))) # vector&lt; signed long &gt;
check(VALUE_OR(array('L', [1, 2, 3]))) # vector&lt; unsigned long &gt;
check(VALUE_OR(array('q', [1, 2, 3]))) # vector&lt; signed long long &gt;
check(VALUE_OR(array('Q', [1, 2, 3]))) # vector&lt; unsigned long long &gt;
check(VALUE_OR(array('f', [1, 2, 3]))) # vector&lt; float &gt;
check(VALUE_OR(array('d', [1, 2, 3]))) # vector&lt; double &gt;
</code></pre></DartMeasurement><DartMeasurement type="text/string" name="test_basic_grammar.source_code"><pre><code class="language-python">def test_basic_grammar():
ipcut = MINIPCUT(IPCut=1.0, Vertices=pvs_dh)
f1 = ISMUON | ipcut
f2 = ISMUON &amp; ipcut
f3 = ipcut | ISMUON
f4 = ipcut &amp; ISMUON
f5 = ~ISMUON
f6 = ~ipcut
check(f2 | ~ISMUON)
check(~ISMUON | f2)
not_empty(f1)
not_empty(f2)
not_empty(f3)
not_empty(f4)
not_empty(f5)
not_empty(f6)
</code></pre></DartMeasurement><DartMeasurement type="text/string" name="test_disabled_logical_operators.source_code"><pre><code class="language-python">def test_disabled_logical_operators():
check((PT &gt; 10 * GeV) &amp; ISMUON)
try:
(PT &gt; 10 * GeV) and ISMUON
except Exception:
pass
else:
raise Exception("Use of logical `and` did not raise an exception.")
try:
(PT &gt; 10 * GeV) or ISMUON
except Exception:
pass
else:
raise Exception("Use of logical `or` did not raise an exception.")
try:
not ISMUON
except Exception:
pass
else:
raise Exception("Use of logical `not` did not raise an exception.")
</code></pre></DartMeasurement><DartMeasurement type="text/string" name="test_functions.source_code"><pre><code class="language-python">def test_functions():
check(fmath.log(old_div(PT, GeV)) &gt; 1.0)
</code></pre></DartMeasurement><DartMeasurement type="text/string" name="test_serialisation.source_code"><pre><code class="language-python">def test_serialisation():
"""A BoundFunctor must be seriasable by the pickle module."""
functor = MINIPCUT(IPCut=1.0, Vertices=pvs_dh)
# Use the same protocol as in `gaudirun.py -o options.pkl`
loaded = pickle.loads(pickle.dumps(functor, protocol=-1))
assert functor.code() == loaded.code()
assert functor.code_repr() == loaded.code_repr()
assert functor.name() == loaded.name()
assert repr(functor) == repr(loaded)
assert str(functor) == str(loaded)
# It is expected that the data dependencies are lost during serialisation;
# see BoundFunctor.__getstate__
assert len(functor.data_dependencies()) &gt; len(loaded.data_dependencies())
assert len(loaded.data_dependencies()) == 0
</code></pre></DartMeasurement>
==================================== ERRORS ====================================
_ ERROR collecting build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py _
/cvmfs/lhcb.cern.ch/lib/lcg/releases/pytest/7.4.0-1f66f/x86_64-el9-gcc13-opt/lib/python3.9/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/cvmfs/lhcb.cern.ch/lib/lcg/releases/pytest/7.4.0-1f66f/x86_64-el9-gcc13-opt/lib/python3.9/site-packages/_pytest/runner.py:372: in <lambda>
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/cvmfs/lhcb.cern.ch/lib/lcg/releases/pytest/7.4.0-1f66f/x86_64-el9-gcc13-opt/lib/python3.9/site-packages/_pytest/doctest.py:547: in collect
module = import_path(
/cvmfs/lhcb.cern.ch/lib/lcg/releases/pytest/7.4.0-1f66f/x86_64-el9-gcc13-opt/lib/python3.9/site-packages/_pytest/pathlib.py:565: in import_path
importlib.import_module(module_name)
/cvmfs/lhcb.cern.ch/lib/lcg/releases/Python/3.9.12-9a1bc/x86_64-el9-gcc13-opt/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
???
<frozen importlib._bootstrap>:1007: in _find_and_load
???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:680: in _load_unlocked
???
/cvmfs/lhcb.cern.ch/lib/lcg/releases/pytest/7.4.0-1f66f/x86_64-el9-gcc13-opt/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
exec(co, module.__dict__)
../../build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py:13: in <module>
from PyConf.Algorithms import FunctorExampleAlg, Gaudi__Examples__IntDataProducer, Gaudi__Examples__VectorDataProducer
E ImportError: cannot import name 'FunctorExampleAlg' from 'PyConf.Algorithms' (unknown location)
_ ERROR collecting build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py _
ImportError while importing test module '/usera/jonesc/LHCb/stack/Master/Rec/build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/cvmfs/lhcb.cern.ch/lib/lcg/releases/Python/3.9.12-9a1bc/x86_64-el9-gcc13-opt/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
../../build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py:13: in <module>
from PyConf.Algorithms import FunctorExampleAlg, Gaudi__Examples__IntDataProducer, Gaudi__Examples__VectorDataProducer
E ImportError: cannot import name 'FunctorExampleAlg' from 'PyConf.Algorithms' (unknown location)
=========================== short test summary info ============================
ERROR ../../build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py
ERROR ../../build.x86_64_v3-el9-gcc13-opt/stack/Rec/Phys/FunctorCore/python/Functors/tests/test_pyconf.py
!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
==================== 21 tests collected, 2 errors in 0.99s =====================
CMake Error at pytest/collect_FunctorCore.pytest.python.Release.cmake:49 (message):
pytest invocation failed!