Tox未找到子模块

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月16日 14:00:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468387.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定