Skip to content

Parametrize question: how to make 1 selenium-webdriver session per 1 test_*() function call irregardless of the number of parametrized sets of data? #2627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
inl-pd-autotest opened this issue Jul 28, 2017 · 9 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@inl-pd-autotest
Copy link

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.

pip list:

appdirs (1.4.3)
certifi (2017.4.17)
chardet (3.0.4)
EasyProcess (0.2.3)
idna (2.5)
lxml (3.8.0)
packaging (16.8)
pip (9.0.1)
py (1.4.33)
pyparsing (2.2.0)
pytest (3.0.7)
pytest-base-url (1.3.0)
pytest-html (1.14.2)
pytest-metadata (1.3.0)
pytest-selenium (1.9.1)
pytest-variables (1.6.0)
PyVirtualDisplay (0.2.1)
requests (2.18.1)
selenium (3.4.1)
setuptools (35.0.1)
six (1.10.0)
urllib3 (1.21.1)
wheel (0.29.0)

CentOS 7x64.

conftest.py:

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
@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Jul 28, 2017
@RonnyPfannschmidt
Copy link
Member

currently that is not supported, #2522 would enable it with a new scope

@inl-pd-autotest
Copy link
Author

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
Copy link
Member

@inl-pd-autotest has this advanced or is still an issue?

@inl-pd-autotest
Copy link
Author

@nicoddemus Well, I got no answer, so it is still an issue.

@RonnyPfannschmidt
Copy link
Member

@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
Copy link
Author

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
Copy link
Member

@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
Copy link
Author

@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
Copy link
Member

its the later and actually good call out - i need to make an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants