[Answered ]-TypeError: TestViews.test_fails() missing 1 required positional argument: 'param'

1👍

StaticLiveServerTestCase inherits unittest.TestCase, which means that you cannot use @pytest.mark.parametrize to expand your test. Fortunately, you can use parameterized instead.

See Does pytest parametrized test work with unittest class based tests? for the related question.

And see https://stackoverflow.com/a/52062473/7058266 for the workaround.

Here’s what your code would look like after swapping out @pytest.mark.parametrize with parameterized:

from parameterized import parameterized
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver import Chrome

class TestViews(StaticLiveServerTestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.driver = Chrome()

    @classmethod
    def tearDownClass(cls):
        if hasattr(cls, 'driver'):
            cls.driver.quit()
            super().tearDownClass()

    @parameterized.expand([
        ['param1'],
        ['param2'],
    ])
    def test_fails(self, param):
        pass

Leave a comment