wolt-python-package-cookiecutter icon indicating copy to clipboard operation
wolt-python-package-cookiecutter copied to clipboard

No __init__.py in tests

Open flying-sheep opened this issue 3 years ago • 2 comments

The tests directory isn't a Python package and shouldn't be imported. Don't have any __init__.py files there.

flying-sheep avatar Aug 11 '22 23:08 flying-sheep

Not sure about this one 🤔 This is from the pytest docs: Screenshot 2022-08-12 at 10 20 08

So, I think it should be fine as we are using the src layout 🙂

jerry-git avatar Aug 12 '22 07:08 jerry-git

we are using the src layout

that means you’re using a src directory wherein your package resides, it has nothing to do with the __init__.py.

To learn about that, plase read these excerpts from the document I linked:

If you need to have test modules with the same name, you might add __init__.py files to your test folder and subfolders, changing them to packages:

Note the If above, and the Note below:

The --import-mode=importlib option (see Import modes) does not have any of the drawbacks above because sys.path is not changed when importing test modules, so users that run into this issue are strongly encouraged to try it.

Regarding the pytest docs, I’ll try to make that more accessible: https://github.com/pytest-dev/pytest/pull/10206

flying-sheep avatar Aug 12 '22 08:08 flying-sheep