MolSSI / cookiecutter-cms

Python-centric Cookiecutter for Molecular Computational Chemistry Packages
MIT License
385 stars 89 forks source link

Tests folder outside Python package? #144

Open RMeli opened 2 years ago

RMeli commented 2 years ago

Hello. I am probably doing something wrong, but I have been battling with this for a while... So far, when using the MolSSI cookiecutter I always moved the tests folder outside the Python package folder just after creating the repository and I never encountered any problems. However, in a recent project I decided to keep the MolSSI cookiecutter structure (tests folder inside the Python package folder) and while at first things seemed to work well, I encountered a problem when I started defining custom command line arguments in conftest.py.

The problem is the following. When I defined a custom command line option in conftest.py using pytest_addoption (to be used in a fixture with "session" scope by passing pytestconfig as argument of the fixture, also defined in the same conftest.py file), the pytest command started failing because the custom option could not be found.

If I run pytest <PACKAGE>/tests, everything works as expected, but running pytest fails. This happens despite having the following pytest.ini file:

[pytest]
minversion = 6.0
testpaths =
    <PACKAGE>/tests/

Everything seems to work as expected if I either move the conftest.py file in the root directory (which I don't think is clean) or if I move the tests directory outside of the Python package and change the pytest.ini file as follows:

[pytest]
minversion = 6.0
testpaths =
    tests/

(as I used to do for other projects).

Am I doing something wrong or the way the cookiecutter is set up does not fully work with a conftest.py file in <PACKAGE>/tests/?

mikemhenry commented 2 years ago

Related to https://github.com/MolSSI/cookiecutter-cms/issues/140

I've ran into the same issues