Pytest未取消选择某些测试(但应位于Pytest.ini中)

2024-10-02 18:28:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经建立了一个测试套件,并且一直在使用pytest和pytest django

提供一些背景信息:我正在尝试使用无头浏览器进行一些集成测试,并让pytest忽略在使用标准(无头)浏览器时使用的某些测试;我想使用真实的可视化浏览器取消选择这些测试,这样它们就不会在我的CI/CD管道中触发

给定下面的例子pytest.ini,如果我运行pytest launcher,它会显示为我预期的那样,有一个测试被取消选择(StandardBrowserTestCases类中只有一个测试)

但是,如果我运行pytest other_app(它也有一个StandardBrowserTestCases类),它不会显示任何被取消选择的内容,StandardBrowserTestCases与其他测试一起运行,而不会被取消选择

[pytest]
addopts =
    --nomigrations
    --cov-config=.coveragerc
    --cov=my_project
    --cov=other_app
    --cov=launcher
    --cov=people
    ; # Ignore the StandardBrowserTestCases - these are only used for local
    ; # development / visual debug and contain no real valuable tests
    --deselect=other_app/tests/test_integrations.py::StandardBrowserTestCases
    --deselect=launcher/tests/test_integrations.py::StandardBrowserTestCases
    --deselect=people/tests/test_integrations.py::StandardBrowserTestCases
    --junitxml=./test-results/junit.xml
    --cov-report html:./test-results/htmlcov
    --html=./test-results/test_results.html
    --self-contained-html
DJANGO_SETTINGS_MODULE = my_project.unit-test-settings
python_files = tests.py test_*.py *_tests.py

我使用--deselect对吗?我如何找出(疑难解答)它为什么在一个应用程序(launcher)上工作,而在另一个应用程序(other_app)上不工作?我如何让pytest从每个应用程序而不是一个应用程序中取消选择这些测试


Tags: pytestapp应用程序pytesthtml浏览器tests