5

Pytest cov 没有从 pyproject.toml 文件中读取其设置。我正在使用 nox,所以我运行测试:

python3 -m nox

即使没有nox,我似乎也有同样的问题。

事实上,在运行之后poetry install

  • poetry run pytest --cov=src通过测试
  • poetry run pytest --cov没有通过测试

特别是,当测试失败时,我有以下输出(输出被削减到最重要的东西):

WARNING: Failed to generate report: No data to report.

/Users/matteo/Library/Caches/pypoetry/virtualenvs/project-Nz69kfmJ-py3.7/lib/python3.7/site-packages/pytest_cov/plugin.py:271: PytestWarning: Failed to generate report: No data to report.

  self.cov_controller.finish()


---------- coverage: platform darwin, python 3.7.7-final-0 -----------

FAIL Required test coverage of 100.0% not reached. Total coverage: 0.00%

此处有可重现错误的代码。要运行它,您需要安装诗歌安装 nox

4

1 回答 1

3

将评论变成答案:

检查目录的当前处理src。现在,它似乎是一个名称空间包,这不是您想要的。切换到src布局:

# pyproject.toml

[tool.poetry]
...
packages = [
    { include = 'project', from = 'src' }
]

[tool.coverage.run]
...
source = ['project']

并修复导入test_code.py

from src.project import code

from project import code

或删除src目录:

rootdir
├── project
│   └── __init__.py
└── tests
    └── test_code.py

并修复导入test_code.py

于 2020-07-10T20:27:24.223 回答