在下面的示例中,如何将args of run_tests()传递给pytest.main(...),以便在TestFooBar In test_module.py的测试方法中使用args
my_module.py
def run_tests(args):
# How do I pass parameter 'args' to pytest here.
pytest.main(['-q', '-s', 'test_module.py::TestFooBar'])
test_module.py
class TestFo
我已经核对了和的答案,但他们没有回答我的问题。
显示您必须将capsys作为参数发送,因此,def test_output(capsys): --这也是另一个示例显示的-- 。
但是,None有一个完整的示例,告诉我如何访问capsys
所以在我的例子中,我有一些功能
# import a bunch of other modules
# run a test not calling from terminal
import pytest
def foo():
print('bar')
def test_foo(capsys):
foo(
在尝试使用PyCharm运行shap测试用例时,我无法避免此错误:
/home/user/shap/venv/bin/python /home/user/Desktop/pycharm-community-2021.1.2/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --path /home/user/shap/tests
Testing started at 10:51 a.m. ...
Launching pytest with arguments /home/user/shap/tests in /home/user/sh
当我在pytest.ini中声明具有参数的标记时,在pytest-bdd特性文件中无法识别这一点。没有参数的标记似乎运行良好。
[pytest]
markers =
swr(issue1): link to Software Requirement
smoke: Smoke Test component
简单的特性文件可以很好地工作在@烟雾中
Feature: Trivial Example
@smoke
Scenario: Add a number to another number
Given 7 is set
When 9
我一直在试图找到一种方法来同时使用嘲弄装潢师和闷热的capsys,但我无法找到正确的方法。
import pytest
import requests_mock
@requests_mock.mock()
def test_with_mock(m):
pass
def test_with_capsys(capsys):
pass
# how to write a test that works with both?
是否可以检测标记是否已被排除?
我使用pytest对嵌入式目标运行一些测试。对于一些测试装置,我可以通过epdu控制电源。
对于带有epdu的设置,我想在测试完成后关闭测试设备。
对于没有epdu的设置,使用-m "not power"调用测试,但在这里,power_on夹具不尝试与epdu通信也是至关重要的。
@pytest.fixture(scope='session', autouse=True)
def power_on():
# TODO: just return it called with `-m "not power"`
我想访问从非测试类中传递给pytest的命令行参数。
我将以下内容添加到我的conftest.py文件中
def pytest_addoption(parser): # pragma: no cover
"""Pytest hook to add custom command line option(s)."""
group = parser.getgroup("Test", "My test option")
group.addoption(
"--stack",
h
我正在为一个web应用程序构建一个测试套件。我使用的固定装置如下:
import pytest
from selenium import webdriver
from common import Common
@pytest.fixture(scope='module')
def driver(module, headless=True):
opts = webdriver.FirefoxOptions()
opts.add_argument('--headless') if headless else None
driver = we
我想将一个列表作为参数传递给基于if条件的夹具。有办法这样做吗?
例如,请参阅以下代码。
我想要实现的是,如果我在pytest中将奇数作为命令行参数中的num类型传递,那么作为参数传递给夹具的列表应该是奇数,参数偶数是偶数。
我使用pytest-xdist多次运行这个测试,因此我使用sys.stderr打印输出。
文件名: conftest.py
def pytest_addoption(parser):
parser.addoption('--type', action='store', help='Number of times to rep