It seems like my system cannot access modules from other folders. For example, if i set my directory to
~/Downloads/principles_of_programming/object-oriented-programming/fibonacci
and run
pytest tests/test_fibonacci.py
I get
==================================================== test session starts =====================================================
platform win32 -- Python 3.9.1, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: C:UsersRyanDownloadsprinciples_of_programmingobject-oriented-programming, configfile: setup.cfg
collected 0 items
=================================================== no tests ran in 0.05s ====================================================
ERROR: file or directory not found: tests/test_fibonacci.py
If I change my directory to
~/Downloads/principles_of_programming/object-oriented-programming
and run the test as above I get
==================================================== test session starts =====================================================
platform win32 -- Python 3.9.1, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: C:UsersRyanDownloadsprinciples_of_programmingobject-oriented-programming, configfile: setup.cfg
collected 0 items / 1 error
=========================================================== ERRORS ===========================================================
__________________________________________ ERROR collecting tests/test_fibonacci.py __________________________________________
ImportError while importing test module 'C:UsersRyanDownloadsprinciples_of_programmingobject-oriented-programmingestsest_fibonacci.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
......AppDataLocalProgramsPythonPython39libimportlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
testsest_fibonacci.py:1: in <module>
from fibonacci import fib
E ModuleNotFoundError: No module named 'fibonacci'
================================================== short test summary info ===================================================
ERROR tests/test_fibonacci.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================== 1 error in 0.45s ======================================================
Error Output
question from:
https://stackoverflow.com/questions/66057257/importerrors-and-modulenotfounderror-for-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…