Sample_test.py
@pytest.mark.parametrize(argnames="key",argvalues=ExcelUtils.getinputrows(__name__),scope="session")
def test_execute():
#Do something
conftest.py
@pytest.fixture(name='setup',autouse=True,scope="session")
def setup_test(pytestconfig):
dict['environment']="QA"
As shown in the code above, I need to run the setup fixture before the test_execute method because the getinputrows method requires the environment to read the sheet. Unfortunately, the parametrize fixture gets executed before the setup_test. Is there any way this is possible?
You need to execute the parameter inside the test function, not in the decorator:
@pytest.mark.parametrize("key", [ExcelUtils.getinputrows], scope="session")
def test_execute(key):
key(__name__)
#Do something
or bind __name__
to the function call beforehand, but again, call the function inside your test:
@pytest.mark.parametrize("key", [lambda: ExcelUtils.getinputrows(__name__)], scope="session")
def test_execute(key):
key()
#Do something
Mind you I am not fully understanding what you're doing, so these examples might or might not make sense.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.