MetPX / sarracenia

https://MetPX.github.io/sarracenia
GNU General Public License v2.0
44 stars 22 forks source link

Unit tests broken #1167

Closed reidsunderland closed 1 month ago

reidsunderland commented 1 month ago

I broke the unit tests a while ago, by creating two plugins that have the same name (eumetsat.py) in different directories.

$ pytest tests
=================================================================================================================== test session starts ====================================================================================================================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /net/local/home/sunderlandr/sr3/tests
configfile: pytest.ini
plugins: mock-3.12.0, metadata-3.0.0, depends-1.0.1, bug-1.3.1, html-4.1.1, cov-4.1.0
collected 246 items / 1 error

========================================================================================================================== ERRORS ==========================================================================================================================
_________________________________________________________________________________________________ ERROR collecting sarracenia/flowcb/poll/eumetsat_test.py _________________________________________________________________________________________________
import file mismatch:
imported module 'eumetsat_test' has this __file__ attribute:
  /net/local/home/sunderlandr/sr3/tests/sarracenia/flowcb/authenticate/eumetsat_test.py
which is not the same as the test file we want to collect:
  /net/local/home/sunderlandr/sr3/tests/sarracenia/flowcb/poll/eumetsat_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
================================================================================================================= short test summary info ==================================================================================================================
ERROR tests/sarracenia/flowcb/poll/eumetsat_test.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================================================== 1 error in 2.46s =====================================================================================================================

Apparently using import mode importlib should stop that problem, but when I try it, it creates a ton of other import errors.

https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-an-import-mode

petersilva commented 1 month ago

@gcglinton umm.. is this interesting? We have two classes with the same name, but in different sub-directories... current scheme copies everything to one dir... flattening class hierarchy... so the tests are completely busted right now... any ideas?

gcglinton commented 1 month ago

Just rename the test file to include the parent folder name.

I had to do this with the test files for the sarracenia.flow.report and sarracenia.flowcb.report classes, which are named tests/sarracenia/flow/report__flow_test.py and tests/sarracenia/flowcb/report__flowcb_test.py respectively.