Unable to launch tests with python 3.12

Hi,

I just switch to python 3.12 and I can’t launch tests on tryton_dev.

Here’s my procedure:

  • Cloning tryton_dev: hg clone ssh://hg@foss.heptapod.net/tryton/tryton tryton_dev
  • Creating virtualenv: virtualenv .venv/trytond
  • Switching to virtualenv: source .venv/trytond/bin/activate
  • Getting requirements: .hooks/update_requirements
  • Installing requirements: pip install -r requirements.txt -r requirements-dev.txt -e trytond/ -e proteus/
  • Trying to launch tests on specific module: python -m unittest discover -s trytond.modules.stock.tests

I’m getting this error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.12/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/lib/python3.12/unittest/main.py", line 104, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.12/unittest/main.py", line 130, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib/python3.12/unittest/main.py", line 253, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib/python3.12/unittest/main.py", line 160, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 307, in discover
    raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: 'trytond.trytond.modules.stock.tests'

Thanks for help ! :slight_smile:

This is not a valid module path. The first trytond directory is not a module.

I made a mistake when copying :frowning:, it was:

python -m unittest discover -s trytond.modules.stock.tests

and getting the error

Then what is the error?

Same error:

╰─ python -m unittest discover -s trytond.modules.stock.tests 
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.12/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/lib/python3.12/unittest/main.py", line 104, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.12/unittest/main.py", line 130, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib/python3.12/unittest/main.py", line 253, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib/python3.12/unittest/main.py", line 160, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 307, in discover
    raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: 'trytond.modules.stock.tests'

So it looks like trytond is not importable. If you can not do import trytond.modules.stock.tests in your python console, it is normal that the tests can not be run.

Try launching the tests from the trytond directory.

Launching from the root of the repo result in the first trytond directory being considered as a Namespace. I haven’t looked yet what has changed between 3.11 and 3.12 so that it has this effect.

Indeed, this is working :slight_smile: Thanks.

Indeed in Python 3.11 the toplevel directory can be imported as <module 'trytond' (<_frozen_importlib_external.NamespaceLoader object at 0x7fbd9afc1110>)>.

For me having a PYTHONPATH=trytond import the right file from the top directory of the repository.

1 Like

Indeed, working also this way in the root of the repo:

PYTHONPATH=trytond:proteus python -m unittest discover -s trytond.modules.stock.tests

Thanks :slight_smile:

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