python-control / Slycot

Python wrapper for the Subroutine Library in Systems and Control Theory (SLICOT)
Other
132 stars 42 forks source link

Pytest for a single file/test, fails #210

Closed KybernetikJo closed 1 year ago

KybernetikJo commented 1 year ago

In python-control it's possible to run a single test by

pytest control/tests/bdalg_test.py.

In slycot, running

pytest slycot/tests/test_ab04md.py

fails

__________________________________________________________________________________ ERROR collecting slycot/tests/test_ab04md.py ___________________________________________________________________________________
import file mismatch:
imported module 'slycot.tests.test_ab04md' has this __file__ attribute:
  /home/johannes/.venvs/slycot-dev/lib/python3.10/site-packages/slycot/tests/test_ab04md.py
which is not the same as the test file we want to collect:
  /home/johannes/InnCybernetics/04_Git/python-control-dev/slycot-fork/Slycot/slycot/tests/test_ab04md.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Remark: My very uneducated guess is, that is related to f2py and the submodule slycot._wrapper or/and missing __init__.py, i'm not sure though. I have spent some time on this issue with no success. However, because running all pytests is fast, it is not a big issue, it would be only a nice to have.

bnavigator commented 1 year ago

Yes, because Slycot is not pure python, you always have to recompile and reinstall in your virtual environment. You can then run individual tests by selecting through -k pattern:

cd /home/johannes/InnCybernetics/04_Git/python-control-dev/slycot-fork/Slycot/
rm -rf _skbuild
/home/johannes/.venvs/slycot-dev/bin/pip install -v .
/home/johannes/.venvs/slycot-dev/bin/pytest -k test_ab04md
KybernetikJo commented 1 year ago

Thanks, it works.

I have tried the -k pattern but with the whole path pytest -k slycot/tests/test_ab04md(.py).

pytest -k test_ab04md does the job.

bnavigator commented 1 year ago

Yes but keep in mind that you execute from the installed test_ab04md.py, not the possibly just edited one in your git repository. Unless you get an editable install working, which is not straight forward: https://github.com/scikit-build/scikit-build/issues?q=editable+install

KybernetikJo commented 1 year ago

I will keep that in mind, and at some point in the future i`ll look into editable installation.

Thanks, again.