我有一个带有3 tests的类,我正在使用pytest来使用Selenium运行测试来执行UI操作。
class abc:
def test_1(self):
print("I am test_1 open browser and perform operations")
def test_2(self):
print("I am test_2 open browser and perform operations")
def test_3(self):
print("I am test_3 open br
是否有一种方法将可调用的pytest.mark.parametrize()参数指定为pytest的一个参数,以便只有在选择要运行的测试时才动态生成参数?
为了生成参数,我需要执行一些昂贵的操作,而且我只希望在选择要运行的测试时执行这些操作。
例如,
import pytest
def my_callable():
# do expensive operations here
return [(1, 2), (3, 6)]
# I want my_callable to be called only if test_something
# has been selected
在运行测试之后,pytest中有一个概述: =在1.11秒内通过了=7 我喜欢访问pytest末尾的时间(这里是1.11)。 我已经在这里找到了一些有用的信息: How can I access the overall test result of a pytest test run during runtime? 但与总体测试运行时间不匹配。 我尝试使用def pytest_sessionfinish(会话,退出状态) 我在那里没有找到总的持续时间。 看起来这个值在RunResult对象中。https://docs.pytest.org/en/latest/_modules/_pytest
有没有人知道动态参数化pytest的变通方法。
示例:
resp = []
def test_1():
r = requests.get(<some url>)
resp = <parse a list out of response r>
@pytest.mark.parameterize("response",resp)
def test_2(response):
<Use resp values and pass it one by one to another api>
我在pytest github上遇
在我的pytest脚本中,我需要定制pytest-HTML报告以捕获标准输出,同时将其写入控制台,因为我在自动测试中有用户输入。
test_TripTick.py
import os
import sys
import pytest
from Process import RunProcess
from recordtype import recordtype
from pip._vendor.distlib.compat import raw_input
@pytest.fixture(scope="module")
def Process(request):