CWorthy-ocean / C-Star

C-Star is a python package for setting up and running ocean model simulations, with a particular focus on marine carbon dioxide removal (mCDR) applications.
https://c-star.readthedocs.io
10 stars 4 forks source link

pytest stubbornly collecting from `cstar/externals` #106

Closed TomNicholas closed 2 weeks ago

TomNicholas commented 4 weeks ago

After C-Star has run case.setup() it has downloaded ucla-roms and more into the cstar/externals directory. Running pytest in the top-level directory of the repo will attempt to collect the contents of cstar/externals, which errors because it tries to import some kind of bad python code defined within the uclas-roms repo.

The solution to this should be to just tell pytest to ignore that directory during test collection, using e.g. collect_ignore_glob in conftest.py from this pytest documentation, i.e.

# in conftest.py
collect_ignore_glob = [
    "cstar/cstar_local_config.py",
    "cstar/externals/**",
]

But this doesn't seem to work, cstar/externals is still collected, and so you get an error:

ERROR cstar/externals/ucla-roms/Examples/code_check/test_roms.py - IndexError: list index out of range

I am completely stumped as to why collect_ignore_glob doesn't ignore the glob. I swear it used to work for me locally, but now it doesn't (and I have no idea what's changed). I even tried making a new package with just a conftest.py and a malformed python file and it worked as expected, so I am unable to reproduce the issue outside of cstar.

For now I think we have no choice but to just say that to run the tests you need to explicitly state the correct directory to collect the real tests from, i.e. pytest cstar/tests/**