python - 如何设置 coveragerc 和/或 setup.cfg 以测试具有特定测试位置的包

标签 python unit-testing testing code-coverage python-unittest

我正在对 python 包进行测试,并尝试使用 pytest 进行测试。

该项目具有以下架构:

  • package_name/
    • __init__.py
    • file1.py
    • file2.py
    • ...
  • 测试/
    • test_file1.py
    • test_file2.py
    • ...
  • setup.py
  • setup.cfg
  • .coveragerc

如何设置 pytest 以使用单个命令启动所有测试,例如:

coverage run setup.py test

我尝试了一些设置,但是 pytest 似乎没有在 tests/ 目录中找到测试文件。

最佳答案

您是否尝试运行命令 pytest tests/

您也可以尝试使用标记测试调用:

@pytest.mark.my_tests
class TestsFilaA:
    def test_something():
        pass

    def test_something_else():
        pass

@pytest.mark.my_tests
class TestsFilaB:
    def test_something_b():
        pass

    def test_something_else_b():
        pass

并运行命令pytest -v -m my_tests

关于python - 如何设置 coveragerc 和/或 setup.cfg 以测试具有特定测试位置的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853782/

相关文章:

Python - 如何检查 for 循环中的 bool 值?

unit-testing - 什么是单元测试数字音频生成的好技术

android - 在没有设备的情况下测试和部署 Android 应用程序真的是个坏主意吗?

selenium - 什么是自动化单页应用程序测试用例的最佳工具

python - 如何在Python中的单个正则表达式中搜索正则表达式组中的特定字符串?

python - GAE - 安全数据连接器和任务队列/Cron

python - 如何更改 pyotp.totp 模块的间隔?

c# - 使用两个函数进行单元测试

java - Mockito - 仅模拟一个方法

R:ggplot2 - 每个方面的 Kruskal-Wallis 测试