python-bindings icon indicating copy to clipboard operation
python-bindings copied to clipboard

Moving tests to tox

Open fsimonis opened this issue 1 year ago • 1 comments

In tox, one can run disable the automatic installation of the package and run custom commands to setup an environment.

This should allow us to build the mock locally, then install the bindings and test against them.

https://tox.wiki/en/latest/config.html#skip_install

https://tox.wiki/en/latest/config.html#commands

We may need to LD_PRELOAD the mock though.

fsimonis avatar Sep 04 '24 15:09 fsimonis

As far as I understand this we could have two different setup.py files in tox and we just pick the right one depending on whether we want to test or not. I would suggest the following structure:

python-bindings
├──setup.py
└── test
    └──setup.py

With tox we should be able to setup something along the following lines:

[tox]
envlist = py38, py39, py310

[testenv]
# Define dependencies common for both building and testing
deps =
    cython
    setuptools
    pytest

# Commands for building and installing the library using the main setup.py, 
# and then running tests using 'test/setup.py'
commands =
    # Build and install the library from the root 'python-bindings/setup.py'
    python setup.py install
    # Run tests from the 'test' directory using 'test/setup.py'
    pytest test --setup=python-bindings/test/setup.py

~~(tox.ini proposed by ChatGPT so I defintely need to understand it better and verify that it actually works. But I think it should suffice to sketch the idea.)~~ There is no option pytest test --setup=..., it looks like there are some workarounds to use different setup.py files but at the moment these solutions look to me very complicated and introduce a lot of code duplication.

BenjaminRodenberg avatar Mar 11 '25 13:03 BenjaminRodenberg