
Not recursively including nested modules is a fairly reasonable choice, since it gives users freedom in how they lay out their package in any arbitrary way - anything that is not explicitly listed is not in the package. You can see missing submodule issues in several open source projects, for example dateutil and pytype were both hit by this. Like if your build backend doesn't support it. If you are using something like tox where each invocation is in a dedicated virtual environment, it is probably reasonable to prefer a bare pytest invocation in your test command. You will need to weigh the dangers of environment-related bugs against the dangers of including the local directory on your Python path for yourself. pytest installed for Python 2 when you are expecting Python 3, or an old version of pytest installed somewhere on your path. The main reason you would want to use a module invocation rather than directly invoking pytest is that the pytest alias in your local environment may point to an installation other than the one you are expecting - e.g. As such, only python -m pytest is in danger of testing against your local repository.

For module invocations in general, the local path will always be on sys.path, whereas invocations of pytest will not add the current directory to your Python path. Pytest can be invoked either as a module (using python -m pytest) or as a command line script (using pytest), and these actually treat the local directory differently. Unfortunately, most Python test runners are executed from the repository root, and it's fairly easy for them to default to importing directly from the repository and not from an installed package. We can fix this either by adding mypkg.subpkg to the setup.cfg or by using find_packages (called find: in a setup.cfg file), a function in setuptools for recursively including subpackages. ImportError: cannot import name 'subpkg' from 'mypkg'

$ python -c "from mypkg import subpkg print('Success!')"

If you import mypkg.subpkg when running a script in from the repository root, you will not get an error, but if you run it from any other directory (as your users will), you'll get an ImportErrror! Because module installation is not recursive, this will not install the mypkg.subpkg submodule.
