Replies: 1 comment 1 reply
-
One idea is to use data_1.py: import pytest
@pytest.fixture
def test_mock_data_1():
# create mock data. conftest.py: pytest_plugins = ('data_1', ) test_mock.py: import pytest
@pytest.mark.usefixture('test_mock_data_1')
def test_mock():
assert db[0] == 1 However, in this case, pytest_plugins can be used only in conftest.py that exists in the root directory, so there is a disadvantage that the code of contest.py in the root becomes large in the case of multiple directory configurations as shown below.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi there.
I would like to talk about implementing the test code for the application I am writing.
Since the amount of code that creates mock data is large, the test code and the code that creates mock data are separated.
It looks like this:
In the above example (although quite simplified), fixture is used to create the mock data.
In fact, in the case I'm implementing, the mock data creation function is implemented in conftest.py and called from the test function like a normal fixture.
What I want to do is to further divide the mock data creation function defined in this fixture into files.
In other words, I want to define multiple conftest.py in one directory.
However, according to the specifications of pytest, conftest.py can only be placed once in one directory.
How should I put this fixture in multiple files?
Beta Was this translation helpful? Give feedback.
All reactions