0

I am trying to learn how to work with pytest module.

I have a package called function1 with init.py and code.py files.

There is another folder "tests" with test_code.py file.

When code.py and test_code.py are in the same folder it works fine. But when I try to split them up, running pytest returns:

ModuleNotFoundError: No module named 'function1'

I can create another py file and import function1.code and calling on any function within the code.py file works. So its not a problem with python not being able to find the module.

What am I missing?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • What command are you using to run pytest? – lehiester Apr 22 '19 at 02:45
  • Running "pytest" is what causes the error. I just learned that running "python -m pytest" works. But I don't understand why? –  Apr 22 '19 at 03:04
  • That is strange--it must be a quirk of how the `pytest` command itself is written that makes packages in the working directory undiscoverable. – lehiester Apr 22 '19 at 03:08
  • 2
    Possible duplicate of [PATH issue with pytest 'ImportError: No module named YadaYadaYada'](https://stackoverflow.com/questions/10253826/path-issue-with-pytest-importerror-no-module-named-yadayadayada) – hoefling Apr 22 '19 at 08:26

0 Answers0