Open
Description
When communicating with pytest beginners, it’s common to encounter code like this:
@pytest.fixture()
def test_login():
driver = get_driver()
page = pom.LoginPage(driver)
page.login()
return driver
def test_create_data(test_login):
page = pom.HomePage(test_login)
msg = page.send_data("./data.csv")
assert 'ok' in msg
While the code meets functional requirements:
- executes
login
first, then executescreate_data
. - Uses the same browser instance for all steps.
It also confuses them: Why are there 2 test cases, but only 1 appears in the terminal and reports?
This confusion arises because in most tutorials, blogs, and examples, test cases and fixtures share similarities:
- Both are functions.
- Both can use decorators.
- Both can return values ( pytest <=8.3.3).
- Both can use fixtures.
Currently, using @pytest.mark
in fixtures raises a warning.
Should we also issue a warning when @pytest.fixture
is used for test cases?
This could make it clearer that test cases and fixtures are fundamentally different, and their decorators are not interchangeable.