# Running tests via pytest fails while collecting tests

**URL:** https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860
**Category:** Developer
**Created:** [September 27, 2025, 4:36pm UTC](https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860 "2025-09-27T16:36:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![htgoebel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/htgoebel/32/1256_2.png) [@htgoebel](https://discuss.tryton.org/u/htgoebel)
#### Post date: [September 27, 2025, 4:36pm UTC](https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860/1 "2025-09-27T16:36:08Z")

</div>

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?**

```auto
==================================== 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.

---

<div class="post-metadata">

### Author: ![JCavallo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@JCavallo](https://discuss.tryton.org/u/JCavallo)
#### Post date: [September 30, 2025, 10:10am UTC](https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860/2 "2025-09-30T10:10:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![htgoebel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/htgoebel/32/1256_2.png) [@htgoebel](https://discuss.tryton.org/u/htgoebel)
#### Post date: [September 30, 2025, 6:02pm UTC](https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860/3 "2025-09-30T18:02:53Z")

</div>

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

```auto
pytest --rootdir tests tests

```

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [October 1, 2025, 6:03pm UTC](https://discuss.tryton.org/t/running-tests-via-pytest-fails-while-collecting-tests/8860/4 "2025-10-01T18:03:01Z")

</div>

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