Running tests via pytest fails while collecting tests

Preface: I know that the official way to run the test-suites is using tox resp. unittest. Anyhow, for Guix packaging we use pytest to run the test-suites as this allows to easily exclude test (e.g. those requiring network). This worked well when I last updated Tryton (to 7.0, never published these patches).

When trying to run the testsuite with a guix as of today, even quite simple modules fail. Passing: e.g. currency, currenty-ro; failing: party, currency-rs.

pytests fails during the collection phase already. Any idea what could cause this reason and how to work around it?

==================================== ERRORS ====================================
____________________ ERROR collecting tests/test_module.py _____________________
trytond/modules/currency_rs/tests/test_module.py:4: in <module>
    from trytond.tests.test_tryton import ModuleTestCase
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/gnu/store/_-python-pytest-8.3.3/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:184: in exec_module
    exec(co, module.__dict__)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/tests/test_tryton.py:57: in <module>
    Pool.start()
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/pool.py:108: in start
    register_classes(with_test=cls.test)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/modules/__init__.py:312: in register_classes
    for node in create_graph(get_modules(with_test=with_test)):
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/modules/__init__.py:104: in create_graph
    info = get_module_info(module)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/modules/__init__.py:43: in get_module_info
    with tools.file_open(os.path.join(name, 'tryton.cfg')) as fp:
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/tools/misc.py:49: in file_open
    path = find_path(name, subdir, _test=None)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/tools/misc.py:75: in find_path
    module = import_module(module_name)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/tools/misc.py:44: in import_module
    return ep.load()
/gnu/store/_-python-3.11.11/lib/python3.11/importlib/metadata/__init__.py:202: in load
    module = import_module(match.group('module'))
/gnu/store/_-python-3.11.11/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
trytond/modules/currency_rs/__init__.py:6: in <module>
    from . import currency
trytond/modules/currency_rs/currency.py:34: in <module>
    class Cron(metaclass=PoolMeta):
trytond/modules/currency_rs/currency.py:47: in Cron
    _rs_list_types = Cache(__name__ + '.get_rs_list_types', context=False)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/cache.py:163: in __init__
    super(MemoryCache, self).__init__(*args, **kwargs)
/gnu/store/_-trytond-7.0.36/lib/python3.11/site-packages/trytond/cache.py:95: in __init__
    assert self._name not in self._instances
E   AssertionError

Running pytett with –debug does not give any hint.

I remember trying once and running into the same problem, but I never took the time to dig deeper.

The error probably means that many instances of the pool were started, possibly concurrently, which leads to the assertion error (because the same cache would be registered multiple times).

I would check if pytests concurrently scans for tests, if it is the case just disabling this behaviour could be enough.

I was able to work around (resp. solve) this by running pytest basically like this:

pytest --rootdir tests tests

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.