Reuse of pytest fixtures

I am writing several tests using pytest, many of which have similar lights. I want to put these "global" lights in a single file so that they can be reused in several test files. My first thought was to create a file fixtures.pysuch as

import pytest


@pytest.fixture()
def my_fixture():
    # do something

Now, how can I use this device in my_tests.py?

def test_connect(my_fixture):
    pass

It gives fixture 'my_fixture' not found. I can from fixtures import my_fixture. What is the proposed solution to this situation?

+4
source share
1 answer

Pytest conftest.py. fixtures.py conftest.py.

+6

Source: https://habr.com/ru/post/1684912/


All Articles