使用并发参数 pytest -n=2 test.py 命令没有任何问题,但是一旦把 a 和 b 值用随机数生成,并发执行用例就会报错,求解?
def pytest_generate_tests(metafunc):
if metafunc.cls.__name__ == "TestCase":
datas = metafunc.cls.datas
func_args = datas[metafunc.function.__name__]
keys = sorted(func_args[0])
metafunc.parametrize(keys, [[func_arg[key] for key in keys] for func_arg in func_args])
import random
# a, b = str(random.randint(0, 10000)), str(random.randint(0, 10000))
a, b = 1, 2
class TestCase:
datas = {
"test_01": [
{"cer_name": a, "name": "小明"}
],
"test_02": [
{"cer_name": b, "name": "小华"}
]
}
def test_01(self, cer_name, name):
assert cer_name == 1
def test_02(self, cer_name, name):
assert cer_name == 2