python - Pytest 不取消选择某些测试(但应该在 pytest.ini 中)
问题描述
我已经设置了一个测试套件,并且一直在使用 pytest 和 pytest-django。
提供一些背景知识:我正在尝试使用无头浏览器进行一些集成测试,并让 pytest 忽略在我使用标准(非无头)浏览器时使用的某些测试;我想使用真实的可视浏览器取消选择这些测试,这样它们就不会在我的 CI/CD 管道中触发。
给定pytest.ini
下面的示例,如果我运行pytest launcher
它会显示我期望有 1 个测试被取消选择(StandardBrowserTestCases 类中只有 1 个测试)。
但是,如果我运行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 从每个应用程序中取消选择这些测试,而不仅仅是一个?
解决方案
推荐阅读
- api - 如何使用 SSH 隧道以编程方式与 Restful API 通信
- xml - 按属性对 XML 进行排序
- reactjs - 重定向在 React 中无法正常工作
- python - 错误:grpc._plugin_wrapping:AuthMetadataPluginCallback 引发异常!(gunicorn) 使用 eventlet (async) 工作者时
- sumo - SUMO 的多模式活动生成器 (SAGA) - 运行时出现 KeyError
- java - 在 Talend 中将两个条目行(开始时间和结束时间)连接为单行
- multithreading - [branch] 如何在 HLSL 中执行?
- mysql - MySQL - GROUP BY 不能使用多个 CASE WHEN 语句
- php - 我的注册页面引用而不是提交到数据库
- ruby-on-rails - 当我尝试使用 admin/test_email 测试电子邮件发送时,Redmine 中出现错误 500