Pytest Make Sure Your Test Modules/Packages Have Valid Python Names -- Can't Import

I have this file structure.

When ı wrote pytest in my terminal.

ı have this issue !

ModuleNotFoundError: No module named 'money_transactions_test'
Hint: make sure your test modules/packages have valid Python names.

Why its can't import money_transactions_test ?

1 Answer

If you're sharing objects within your tests the easiest thing would be to make use of conftest.py

However if you must import, since your test files are in the same package directory I recommend specifying a relative import. ie:

from .money_transactions_test import acc_numbers_list
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest