Testing module in new mono repository locally

I wonder how I can test changes to a module locally when using the new mono repository.

PIP_EXTRA_INDEX_URL=https://trydevpi.tryton.org/ tox -epy38-sqlite -c modules/account

fails with

Looking in indexes: https://pypi.org/simple, https://trydevpi.tryton.org/
ERROR: Could not find a version that satisfies the requirement proteus<6.8,>=6.7 (from versions: 1.8.1, …
6.4.0, 6.4.1, 6.6.0, 6.6.1)

which is somewhat obvious since the requirement does not cover .dev versions.

So what are the tricks required to run the tests locally?

Just run python -m unittest on the module to test: Testing — trytond latest documentation
There is no point to use tox for development.

$ python -m unittest
ModuleNotFoundError: No module named 'trytond'

which is as expected, since there is no environment set up.

The link you gave does not spend a single work on how to set up a development environment. Neither does Tryton - How to Develop, nor How to install Tryton — trytond latest documentation. This is esp. true since with the new mono repo the developement environment is quite different from a “normal” installation.

I would appreciate if you could add the the missing steps to the later.

There is nothing special, trytond can be run from the source as long as it is in the PYTHONPATH.

$ PYTHONPATH=$PWD/trytond:$PWD:proteus python -m unittest modules/association/tests/__init__.py 
ModuleNotFoundError: No module named 'sql'

Next try:

$ python -m venv _venv
$ . _venv/bin/activate
(_venv)$ pip install -e proteus trytond  # install ”editable”
(_venv)$ .hooks/link_modules
(_venv)$ python -m unittest modules/account/tests/__init__.py 
ModuleNotFoundError: No module named 'trytond.modules.currency'
(_venv)$ ls -dF trytond/trytond/modules/cur*
trytond/trytond/modules/currency@     trytond/trytond/modules/currency_rs@

You can not mix installation and non-installation.

Well, uninstalled did not work either. So what is the proper way to set up a development environment for the mono repo?

There is no proper way. Use the way that suite your needs: use direct source, install every thing etc.
There is nothing special about the monorepo.

Personally, I just do:

hg clone https://foss.heptapod.net/tryton/tryton
cd tryton
python -m venv --prompt tryton .venv
source .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
PYTHONPATH=trytond:tryton:proteus python -m unittest discover -s trytond.modules.party

I do something very similar but installing server and proteus from sources with:

pip install -r requirements.txt -r requirements-dev.txt -e trytond/ -e proteus/

So all the packages are available inside the virtualenv and you do not need to care about the path.
This have the benefit that tests can be run from any folder, you just need to have the virtualenv activated.


And I do it differently too :slight_smile:

I use pew to manage all my virtual environments in one place (it was really useful before the mono repo but now that everything is in the same place I have thought about using venv directly).

But I don’t put trytond and proteus in the environment, so I rely on a shell script to launch the tests (and notify me when the tests failed with notify-send because I don’t stare at the tests running).

As you can see there is as many ways as there are developers in this thread :smiley:.

Found my error: I used -e proteus tryton where it should have been -e proteus -e tryton (second -e).
Also installing from the requirements-file saved a lot of try-and-error.

I’ll propose an update to the website to clarify this.

Anyhow: There is a tox.ini file in every module’s directory. I would expect running just tox -e py38 to run the tests for this module. This is how tox works. If this does not work I suggest removing the tox.tini file, as it distracts developers.

PS: --prompt tryton was new to me. I like it, thanks.