You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parametrize question: how to make 1 selenium-webdriver session per 1 test_*() function call irregardless of the number of parametrized sets of data? #2627
I have conftest.py with a class that starts a selenium webdriver function.
I have test_something.py module with test_a() and test_b() functions.
Each of the functions is parametrized (uses @pytest.mark.parametrize fixture), so that each of them runs twice with different sets of parameters.
Problem: I need to make 1 webdriver session match 2 parametrized calls for each test function separately. In other words: webdriver_session1: test_a(param1), test_a(param2); webdriver_session2: test_b(param1), test_b(param2).
If I create an instance of the class outside the test functions - then I get 1 webdriver session per MODULE (1 session per 2 functions, instead of 1 session per 1 function).
If I create an instance of the class inside the test functions - then I get 1 webdriver sessions per PARAMETRIZED CALL (2 sessions per 1 function, instead of 1 session per 1 function).
I thought that wrapping test functions into test_wrapper_a() and test_wrapper_b() would help, but this way parametrizing doesn't work.
class Driver():
def __init__(self):
self.wd = webdriver.Chrome()
def __del__(self):
self.wd.quit()
test_module_fail_1.py:
from conftest import Driver
@pytest.mark.parametrize('arg', [('set1'),('set2')])
def test_a(arg):
o = Driver() # I want 1 call of that per the whole function, not per 1 parametrized call of this function.
assert True
@pytest.mark.parametrize('arg', [('set1'),('set2')])
def test_b(arg):
o = Driver() # I want 1 call of that per the whole function, not per 1 parametrized call of this function.
assert True
test_module_fail_2.py:
from conftest import Driver
def test_a_wrapper():
o = Driver()
@pytest.mark.parametrize('arg', [('set1'),('set')])
def test_a(arg): # This way pytest doesn't call this function, even if I rename test_a_wrapper to a_wrapper.
assert True
def test_b_wrapper():
o = Driver()
@pytest.mark.parametrize('arg', [('set1'),('set')])
def test_b(arg): # This way pytest doesn't call this function, even if I rename test_b_wrapper to b_wrapper.
assert True
Thank you.
I could replace the currently non-working parametrizing mechanism inside the wrapper function with a simple for loop that makes calls of the wrapped function as many times as I need, but all the calls would together count only as a single test. Could you provide some mechanism so that I could artificially mark successful tests finishes?
@inl-pd-autotest you could fake it by having a fixture that hold a browser and a key and at the lowert level request the browser with the "key" and drop it every time the key doesnt match
I just noticed that ticket #2522 referenced in the first comment to this ticket has now been resolved.
Does it mean that what I initially wanted by this ticket is now possible to do via some new scope?
How?
@inl-pd-autotest unfortunately its only half-fixed - we need a major release to fix the rest as far as i can tell (its not availiable as scope or in the node tree, so it cant help you with fixtures
@RonnyPfannschmidt not sure I understand: is it already fixed, but just not in a release yet, or is it only half-fixed and there are still things to fix first before a new release with a new scope could come out?
If the latter is the case - could you, please, reference related tickets numbers?
So that I'd know what to wait for.
Activity
RonnyPfannschmidt commentedon Jul 28, 2017
currently that is not supported, #2522 would enable it with a new scope
inl-pd-autotest commentedon Jul 29, 2017
Thank you.
I could replace the currently non-working parametrizing mechanism inside the wrapper function with a simple for loop that makes calls of the wrapped function as many times as I need, but all the calls would together count only as a single test. Could you provide some mechanism so that I could artificially mark successful tests finishes?
nicoddemus commentedon Sep 2, 2018
@inl-pd-autotest has this advanced or is still an issue?
inl-pd-autotest commentedon Sep 3, 2018
@nicoddemus Well, I got no answer, so it is still an issue.
RonnyPfannschmidt commentedon Sep 3, 2018
@inl-pd-autotest you could fake it by having a fixture that hold a browser and a key and at the lowert level request the browser with the "key" and drop it every time the key doesnt match
inl-pd-autotest commentedon Sep 3, 2018
I just noticed that ticket #2522 referenced in the first comment to this ticket has now been resolved.
Does it mean that what I initially wanted by this ticket is now possible to do via some new scope?
How?
RonnyPfannschmidt commentedon Sep 3, 2018
@inl-pd-autotest unfortunately its only half-fixed - we need a major release to fix the rest as far as i can tell (its not availiable as scope or in the node tree, so it cant help you with fixtures
inl-pd-autotest commentedon Sep 3, 2018
@RonnyPfannschmidt not sure I understand: is it already fixed, but just not in a release yet, or is it only half-fixed and there are still things to fix first before a new release with a new scope could come out?
If the latter is the case - could you, please, reference related tickets numbers?
So that I'd know what to wait for.
RonnyPfannschmidt commentedon Sep 3, 2018
its the later and actually good call out - i need to make an issue