Skip to content
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

pytest.mark.parametrize is broken #395

Closed
frafra opened this issue Oct 19, 2019 · 5 comments
Closed

pytest.mark.parametrize is broken #395

frafra opened this issue Oct 19, 2019 · 5 comments
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. workaround exists You can reach your destination if you do this...

Comments

@frafra
Copy link
Contributor

frafra commented Oct 19, 2019

pytest.mark.parametrize works with pytest:

import pytest
class TestParametrized:
    @pytest.mark.parametrize('value', [0, 1])
    def test(self, value):
        pass

...but it doesn't with seleniumbase:

from seleniumbase import BaseCase
import pytest
class TestParametrized(BaseCase):
    @pytest.mark.parametrize('value', [0, 1])
    def test(self, value):
        pass

Error message:

[...]
                with outcome.testPartExecutor(self, isTest=True):
>                   testMethod()
E                   TypeError: test() missing 1 required positional argument: 'value'

/usr/lib64/python3.7/unittest/case.py:628: TypeError
@mdmintz
Copy link
Member

mdmintz commented Oct 19, 2019

@frafra See https://github.com/seleniumbase/SeleniumBase/blob/master/examples/parameterized_test.py which lets you parameterize tests with the “parameterized” package.

@mdmintz
Copy link
Member

mdmintz commented Oct 20, 2019

@frafra To invoke pytest fixtures directly, such as pytest.mark.parameterize, see this example:

import pytest


@pytest.mark.parametrize('value', ["pytest", "selenium"])
def test_sb_fixture_with_no_class(sb, value):
    sb.open("https://google.com/ncr")
    sb.update_text('input[title="Search"]', value + '\n')
    sb.assert_text(value, "div#center_col")


class Test_SB_Fixture():
    @pytest.mark.parametrize('value', ["pytest", "selenium"])
    def test_sb_fixture_inside_class(self, sb, value):
        sb.open("https://google.com/ncr")
        sb.update_text('input[title="Search"]', value + '\n')
        sb.assert_text(value, "div#center_col")

Its uses seleniumbase as a fixture to allow the use of any pytest fixture. (sb fixture)

@mdmintz
Copy link
Member

mdmintz commented Oct 20, 2019

Here's an example of correct pytest.mark.parameterize usage with SeleniumBase:
https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_pytest_parameterize.py

@mdmintz mdmintz closed this as completed Oct 22, 2019
@frafra
Copy link
Contributor Author

frafra commented Oct 22, 2019

Thank you :-) but pytest.mark.parameterize does not work with Seleniumbase if you decorate a function inside a class, as my first comment tried to show.

@mdmintz
Copy link
Member

mdmintz commented Oct 22, 2019

@frafra That's due to a bug with pytest itself. See pytest-dev/pytest#541 I've created a few different workarounds: 1, by using the parameterized package; and 2, by creating the sb fixture for seleniumbase, which passes the unittest.TestCase class as a fixture into pytest tests. Without these workarounds, the issue needs to be corrected on the pytestside, and the maintainers of that probably could fix it if they look how I passed all of seleniumbase's unittest.TestCase methods through the fixture, instead of a direct class import.

samuel500 referenced this issue in konfuzio-ai/konfuzio-sdk Aug 30, 2022
@mdmintz mdmintz added external Outside SeleniumBase's scope. / Ask somewhere else. workaround exists You can reach your destination if you do this... labels Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. workaround exists You can reach your destination if you do this...
Projects
None yet
Development

No branches or pull requests

2 participants