Running pytest.main twice from the same python script #11536
Unanswered
nadavchernin
asked this question in
General
Replies: 1 comment 3 replies
-
This is in line with how python work's Imports get cached |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have script which run pytest.main twice.
There is a test which needs to be run in each session with different parametrized values
In parametrizing decorator i use function get_time:
import datetime
import pytest
def get_time():
time_list = [datetime.datetime.now().second,
datetime.datetime.now().second + 1]
return time_list
@pytest.mark.parametrize('time',get_time())
def test_1(time):
print(time)
The main script as follows:
import pytest
sq = ["--collect-only", # Here are pytest flags
"rx_setup_tests/test_twice_parametrize.py::test_1",
]
pytest.main(sq)
sq = ["--collect-only", # Here are pytest flags
"rx_setup_tests/test_twice_parametrize.py::test_1",
]
pytest.main(sq)
The function get_time is called only once and the parameterized arguments stay the same in the second session.
Please your advice
Thank you very much, Nadav
Beta Was this translation helpful? Give feedback.
All reactions