Closed epogrebnyak closed 8 years ago
Same mechanism explained here: https://github.com/epogrebnyak/rosstat-kep-data/blob/tmpdir_example/kep/test/test_yaml_import.py#L46-L68
@epogrebnyak Arguments of test functions (e.g. test_database) are test fixtures. They can be defined in the same module, or in special file conftest.py, which serves as a standard place to store fixtures.
The advantage of keeping fixtures in the same test file is readability. Also, some fixtures may be too specific to store them in conftest.py
.
The advantage of keeping fixtures in conftest.py
is that they are automatically available for all tests.
Yes, it may seem confusing at first, but if you remember that all test function arguments are fixtures, and all fixtures are stored either in the same file or in conftest.py
, it becomes easy to find them.
For the sake of readability and maintainability, we can add docstrings to test methods, explaining what kind of fixtures they use. This will also be automatically reflected in HTML documentation.
There is no real difference between @pytest.fixture
and @pytest.yield_fixture
, they are two ways to do the same thing. We may use @pytest.yield_fixture
everywhere for consistency, but that's purely cosmetic.
If you have further questions about fixtures, feel free to contact me in Upwork or Skype.
Please specify what exactly should I do in this issue.
- Желательно, пока нет явной необходимости применять фикстуры - не применять их. Как только у нас будет несколько тестов, читающих из файла, можно будет вынести чтение в фикстуру.
@alexanderlukanin13: need demonstrate - https://github.com/epogrebnyak/rosstat-kep-data/blob/master/kep/test/test_database.py#L6