英文:
Tox not finding submodules
问题
I am having some issues running pytest through tox due to it not recognizing submodules.
The error that keeps coming up is ModuleNotFoundError: No module named 'app.api'
I'm not really sure how to fix this because it is working fine when I install the package and run pytest myself.
Any help would be greatly appreciated.
My directory structure:
|- project
|- src
|- app
|- api
|- core
|- tests
|- setup.py
|- tox.ini
|- setup.cfg
tox.ini
[tox]
minversion = 3.27.0
envlist = py311
isolated_build = True
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
-r{toxinidir}/requirements_dev.txt
-r{toxinidir}/requirements.txt
commands =
pytest --basetemp={envtmpdir}
setup.py
from setuptools import find_packages, setup
if __name__ == "__main__":
setup(packages=find_packages(exclude=["tests"]))
setup.cfg
[metadata]
name = app
version = 0.0.1
[options]
packages = app
python_requires = >=3.11
package_dir =
=src
zip_safe = no
[options.extras_require]
testing =
pytest>=6.0
pytest-cov>=2.0
tox>=3.24
英文:
I am having some issues running pytest through tox due to it not recognising submodules.
The error that keeps coming up is ModuleNotFoundError: No module named 'app.api'
I'm not really sure how to fix this because it is working fine when I install the package and run pytest myself.
Any help would be greatly appreciated.
My directory structure:
|- project
|- src
|- app
|- api
|- core
|- tests
|- setup.py
|- tox.ini
|- setup.cfg
tox.ini
[tox]
minversion = 3.27.0
envlist = py311
isolated_build = True
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
-r{toxinidir}/requirements_dev.txt
-r{toxinidir}/requirements.txt
commands =
pytest --basetemp={envtmpdir}
setup.py
from setuptools import find_packages, setup
if __name__ == "__main__":
setup(packages=find_packages(exclude=["tests"]))
setup.cfg
[metadata]
name = app
version = 0.0.1
[options]
packages = app
python_requires = >=3.11
package_dir =
=src
zip_safe = no
[options.extras_require]
testing =
pytest>=6.0
pytest-cov>=2.0
tox>=3.24
答案1
得分: 1
So after spending some time (reluctantly) reading the tox docs I discovered that the package is built as defined in the pyproject.toml
where I had it set in setup.cfg
The text I had to add to pyproject.toml
was this:
[tool.setuptools.packages.find]
where = ["src"]
include = ["app*"]
exclude = ["app.tests*"]
Tox now builds the app all good.
英文:
So after spending some time (reluctantly) reading the tox docs I discovered that the package is built as defined in the pyproject.toml
where I had it set in setup.cfg
The text I had to add to pyproject.toml
was this:
[tool.setuptools.packages.find]
where = ["src"]
include = ["app*"]
exclude = ["app.tests*"]
Tox now builds the app all good.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论