Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest make sure your test modules/packages have valid Python names -- can't import

I have this file structure.

enter image description here

When ı wrote pytest in my terminal.

ı have this issue !

enter image description here

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 ?

like image 642
Selman Avatar asked Jul 01 '26 04:07

Selman


2 Answers

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
like image 134
Teejay Bruno Avatar answered Jul 04 '26 04:07

Teejay Bruno


Try creating a file "pytest.ini" and adding the following entry:

[pytest] pythonpath = . test

like image 26
shirmalov Avatar answered Jul 04 '26 04:07

shirmalov