1

I am missing probably something obvious, but I do not see it.

I have the file conftest.py in where I define a fixture:

import pytest

@pytest.fixture
def file_tests():
    return "tests.json"

And then I have my test as follows (file test1.py) in the same folder as conftest.py:

import pytest
from seleniumbase import BaseCase

class MyTestClass(BaseCase):

    def test_basics(self, file_tests):
        print(file_tests)

But when I run

py.test test1.py

I get an error

E       TypeError: test_basics() missing 1 required positional argument: 'file_tests'

What obvious thing am I missing?

Maybe it is "interfering" with the seleniumbase class?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • Apparently the test case methods aren't supposed to take any arguments. – mkrieger1 Aug 31 '21 at 07:10
  • But I have some other pytest code, where I created the test in exactly that way! – Alex Aug 31 '21 at 07:13
  • 3
    `seleniumbase` uses `unittest` underneath, subclassing `unittest.TestCase`. `pytest` support of using fixtures with `unittest`-style tests is very limited, see [unittest.TestCase Support](https://docs.pytest.org/en/6.2.x/unittest.html). When subclassing from `TestCase`, you can inject fixtures as test case instance attributes, see [my other answer for an example](https://stackoverflow.com/a/50375022/2650249). – hoefling Aug 31 '21 at 07:36

1 Answers1

2

Fixtures wont work with test classes inheriting from BaseCase since it is a subclass of unittest.TestCase and pytest doesn't support fixtures for unittest.TestCase.

Tzane
  • 2,752
  • 1
  • 10
  • 21