The tests with tox aren't working

Hi,

When I try to run tox, I get an error in test_tryton.py:

root@dfa338eb8779:/code# tox -e py310-sqlite
.pkg: _optional_hooks> python /usr/local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta legacy
.pkg: get_requires_for_build_editable> python /usr/local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta legacy
.pkg: build_editable> python /usr/local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta legacy
py310-sqlite: install_package> python -I -m pip install --force-reinstall --no-deps /code/.tox/.tmp/package/3/request-6.8.0-0.editable-py3-none-any.whl
py310-sqlite: commands[0]> coverage run ‘–omit=/tests/’ -m xmlrunner discover -s tests

Running tests…

/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/database.py:428: UserWarning: The path specified in the URI will be overridden
warnings.warn(“The path specified in the URI will be overridden”)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:296: UserWarning: Unable to remove not null with SQLite backend
warnings.warn(‘Unable to remove not null with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:287: UserWarning: Unable to drop foreign key with SQLite backend
warnings.warn(‘Unable to drop foreign key with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:301: UserWarning: Unable to add constraint with SQLite backend
warnings.warn(‘Unable to add constraint with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:212: UserWarning: Unable to set default on column with SQLite backend
warnings.warn(‘Unable to set default on column with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:294: UserWarning: Unable to set not null with SQLite backend
warnings.warn(‘Unable to set not null with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:284: UserWarning: Unable to add foreign key with SQLite backend
warnings.warn(‘Unable to add foreign key with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:304: UserWarning: Unable to drop constraint with SQLite backend
warnings.warn(‘Unable to drop constraint with SQLite backend’)
/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/backend/sqlite/table.py:324: UserWarning: Can not create index with parameters
warnings.warn(“Can not create index with parameters”)

======================================================================
ERROR [0.000s]: setUpClass (test_module.RequestTestCase)

Traceback (most recent call last):
File “/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/tests/test_tryton.py”, line 253, in setUpClass
activate_module(modules, lang=cls.language)
File “/code/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/tests/test_tryton.py”, line 88, in activate_module
assert len(records) == len(modules)
AssertionError




Ran 0 tests in 9.998s

FAILED (errors=1)

Generating XML reports…
/code/.tox/py310-sqlite/lib/python3.10/site-packages/coverage/control.py:958: CoverageWarning: No data was collected. (no-data-collected); see 

self._warn(“No data was collected.”, slug=“no-data-collected”)
py310-sqlite: exit 1 (11.84 seconds) /code> coverage run ‘–omit=/tests/’ -m xmlrunner discover -s tests pid=54
py310-sqlite: FAIL code 1 (15.29=setup[3.45]+cmd[11.84] seconds)
evaluation failed 
 (15.51 seconds)

It seems that tox can’t activate our module.

In fact, I couldn’t find our module in the tox environment:

root@dfa338eb8779:/code# ls -altr .tox/py310-sqlite/lib/python3.10/site-packages/trytond/modules/
total 56
drwxr-xr-x 5 root root 4096 Mar 3 22:18 ldap_authentication
drwxr-xr-x 8 root root 4096 Mar 3 22:18 currency
drwxr-xr-x 8 root root 4096 Mar 3 22:18 country
drwxr-xr-x 7 root root 4096 Mar 3 22:18 party
drwxr-xr-x 7 root root 4096 Mar 3 22:18 company
drwxr-xr-x 7 root root 4096 Mar 3 22:18 product
drwxr-xr-x 7 root root 4096 Mar 3 22:18 stock
-rw-r–r-- 1 root root 15295 Mar 3 22:18 init.py
drwxr-xr-x 2 root root 4096 Mar 3 22:18 pycache
drwxr-xr-x 10 root root 4096 Mar 3 22:18 .
drwxr-xr-x 13 root root 4096 Mar 3 22:18 ..

Can anyone give me any ideas? Thanks.

This is usually because you need to specify a Python package in the “requires” section of setup.py.
I seem to remember that this also happened to me if there was an incorrect import in the __init__.py or tests/__init__.py file

The error is because your test requests to activate some modules but they are not all installed in the virtualenv.
It is probably because of the missing of an optional test dependency.

I should clarify that this also occurs with the account_es_facturae module (downloaded from here).

In a Docker container with Python 3.10, I ran tox -e py310-sqlite inside the downloaded module’s directory, obtaining similar errors:

======================================================================
ERROR: setUpClass (account_es_facturae.tests.test_module.AccountEsFacturaeTestCase)

Traceback (most recent call last):
File “/code/account_es_facturae/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/tests/test_tryton.py”, line 253, in setUpClass
activate_module(modules, lang=cls.language)
File “/code/account_es_facturae/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/tests/test_tryton.py”, line 88, in activate_module
assert len(records) == len(modules)
AssertionError

======================================================================
FAIL: /code/account_es_facturae/tests/scenario_account_es_facturae.rst
Doctest: scenario_account_es_facturae.rst

Traceback (most recent call last):
File “/usr/local/lib/python3.10/doctest.py”, line 2221, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for scenario_account_es_facturae.rst
File “/code/account_es_facturae/tests/scenario_account_es_facturae.rst”, line 0




File “/code/account_es_facturae/tests/scenario_account_es_facturae.rst”, line 12, in scenario_account_es_facturae.rst
Failed example:
config = activate_modules(‘account_es_facturae’)
Exception raised:
Traceback (most recent call last):
File “/usr/local/lib/python3.10/doctest.py”, line 1350, in __run
exec(compile(example.source, filename, “single”,
File “<doctest scenario_account_es_facturae.rst[2]>”, line 1, in 
config = activate_modules(‘account_es_facturae’)
File “/code/account_es_facturae/.tox/py310-sqlite/lib/python3.10/site-packages/trytond/tests/tools.py”, line 24, in activate_modules
assert len(records) == len(modules)
AssertionError




Ran 1 test in 25.295s

FAILED (failures=1, errors=1)

What could be missing?

Thanks in advance!

I just tested the module with 6.8.0 tag (which is no longer supported btw) and it works for me without any issues.The only differnce I see is that I’m using python 3.14 (which should not be relevant)

Probably the problem is related to some missing module on your installation. What happens if you run the command tox -e py310-sqlite -r to force the recreation of the virtualenv?

Thanks everyone for your replies.

I had the same problem with Python 3.10 and 3.12 using version 6.8 of the module (even with tox -e py310-sqlite -r). However, with Python 3.12 and the latest version of the module (7.7), the tests worked.

To run the tests with Python 3.14, you had to edit tox.ini, right?