Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presence of empty __init__.py breaks test discovery in hard-to-diagnose ways #9300

Open
h-vetinari opened this issue Nov 12, 2021 · 0 comments
Labels
topic: collection related to the collection phase

Comments

@h-vetinari
Copy link

h-vetinari commented Nov 12, 2021

Hey all

I'm trying to add another package to conda-forge, and ran into collection problems when attempting to run the upstream test suite:

==================================== ERRORS ====================================
______ ERROR collecting tensorflow_addons/callbacks/tests/run_all_test.py ______
import file mismatch:
imported module 'run_all_test' has this __file__ attribute:
  $SRC_DIR/tensorflow_addons/activations/tests/run_all_test.py
which is not the same as the test file we want to collect:
  $SRC_DIR/tensorflow_addons/callbacks/tests/run_all_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

The first thing that caught my eye were the weird kind of test wrappers that tf-addons is using (my guess from searching their repo is that this is for bazel compatibility, and hence not so relevant due to the relative rarity of that in python; edit: beyond the convoluted definition, the underlying issue for these is #9301), but removing those still left me with similarly cryptic errors:

==================================== ERRORS ====================================
_ ERROR collecting tensorflow_addons/callbacks/tests/avg_model_checkpoint_test.py _
ImportError while importing test module '$SRC_DIR/tensorflow_addons/callbacks/tests/avg_model_checkpoint_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../[...]/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.avg_model_checkpoint_test'

I then got curious about No module named 'tests.avg_model_checkpoint_test', especially because the upstream test modules (an example) looked alright, and that module that was supposedly not being found didn't appeared anywhere.

By chance, I noticed that the test folders contain empty __init__.py files, and due to some dim awareness of the issues around imports, I decided on a whim to see what happens if I remove them - turns out collection succeeds then! 🥳

From looking around the issue tracker (and said awareness of import troubles in python), I believe this issue is probably quite thorny, so the underlying problem is probably captured in other issues already: #3396 #5147 #8332

However, I'm hoping that a possible fix for empty __init__.py might be easier than that, and at the very least, I think the warning should be improved, because it's really not obvious what's causing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase
Projects
None yet
Development

No branches or pull requests

2 participants