2017-01-18 21:39:47 +08:00
|
|
|
import pprint
|
2020-05-01 19:40:17 +08:00
|
|
|
from typing import List
|
|
|
|
from typing import Tuple
|
2018-06-16 00:13:45 +08:00
|
|
|
|
2018-10-25 15:01:29 +08:00
|
|
|
import pytest
|
|
|
|
|
2018-06-16 00:13:45 +08:00
|
|
|
|
2017-01-18 21:39:47 +08:00
|
|
|
def pytest_generate_tests(metafunc):
|
2018-06-16 00:13:45 +08:00
|
|
|
if "arg1" in metafunc.fixturenames:
|
|
|
|
metafunc.parametrize("arg1", ["arg1v1", "arg1v2"], scope="module")
|
2017-01-18 21:39:47 +08:00
|
|
|
|
2018-06-16 00:13:45 +08:00
|
|
|
if "arg2" in metafunc.fixturenames:
|
|
|
|
metafunc.parametrize("arg2", ["arg2v1", "arg2v2"], scope="function")
|
2017-01-18 21:39:47 +08:00
|
|
|
|
2018-06-16 00:13:45 +08:00
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2017-01-18 21:39:47 +08:00
|
|
|
def checked_order():
|
2020-10-06 09:13:05 +08:00
|
|
|
order: List[Tuple[str, str, str]] = []
|
2017-01-18 21:39:47 +08:00
|
|
|
|
|
|
|
yield order
|
|
|
|
pprint.pprint(order)
|
2018-06-26 23:00:11 +08:00
|
|
|
assert order == [
|
2021-03-07 21:57:19 +08:00
|
|
|
("issue_519.py", "fix1", "arg1v1"),
|
2018-06-26 23:00:11 +08:00
|
|
|
("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
|
|
|
("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),
|
|
|
|
("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
|
|
|
("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),
|
2021-03-07 21:57:19 +08:00
|
|
|
("issue_519.py", "fix1", "arg1v2"),
|
2018-06-26 23:00:11 +08:00
|
|
|
("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
|
|
|
("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),
|
|
|
|
("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
|
|
|
("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),
|
|
|
|
]
|
2018-06-16 00:13:45 +08:00
|
|
|
|
|
|
|
|
2020-06-25 19:05:46 +08:00
|
|
|
@pytest.fixture(scope="module")
|
2017-01-18 21:39:47 +08:00
|
|
|
def fix1(request, arg1, checked_order):
|
2018-06-16 00:13:45 +08:00
|
|
|
checked_order.append((request.node.name, "fix1", arg1))
|
|
|
|
yield "fix1-" + arg1
|
2017-01-18 21:39:47 +08:00
|
|
|
|
2018-06-16 00:13:45 +08:00
|
|
|
|
2020-06-25 19:05:46 +08:00
|
|
|
@pytest.fixture(scope="function")
|
2017-01-18 21:39:47 +08:00
|
|
|
def fix2(request, fix1, arg2, checked_order):
|
2018-06-16 00:13:45 +08:00
|
|
|
checked_order.append((request.node.name, "fix2", arg2))
|
|
|
|
yield "fix2-" + arg2 + fix1
|
|
|
|
|
2017-01-18 21:39:47 +08:00
|
|
|
|
|
|
|
def test_one(fix2):
|
|
|
|
pass
|
|
|
|
|
2018-06-16 00:13:45 +08:00
|
|
|
|
2017-01-18 21:39:47 +08:00
|
|
|
def test_two(fix2):
|
|
|
|
pass
|