For Python 3.
I just started learning Python. I have PHP and Ruby background.
Currently very confused with modules, __init__
and python -m
.
At the moment I have the following:
modules/practice.py
tests/test_practice.py
In practice.py
class First:
def attempt(self):
return 'attempted'
In test_practice.py
from modules.practice import First
class TestMain:
def test_attempt(self):
first = First()
attempted = first.attempt()
assert attempted is 'attempted'
When I run pytest
I get an error ModuleNotFoundError: No module named 'modules
When I run python -m pytest
test is green.
However, if I add __init__.py
files in modules and tests, both are green.
After trying to find out answers on my own I confess I am not sure I am getting it.
Why pytest
does not work without __init__
?
When working on a project, when people assume python -m
will be used and when people add the __init__.py
files instead?