epogrebnyak / data-rosstat-kep

Time series dataset of Rosstat Short-term Economic Indicators ("KEP") publication
http://www.gks.ru/wps/wcm/connect/rosstat_main/rosstat/ru/statistics/publications/catalog/doc_1140080765391
6 stars 6 forks source link

Testing: using fixtures #69

Closed epogrebnyak closed 8 years ago

epogrebnyak commented 8 years ago

@alexanderlukanin13: need demonstrate - https://github.com/epogrebnyak/rosstat-kep-data/blob/master/kep/test/test_database.py#L6

epogrebnyak commented 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

alexanderlukanin13 commented 8 years ago

@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.

epogrebnyak commented 8 years ago
  1. Желательно, пока нет явной необходимости применять фикстуры - не применять их. Как только у нас будет несколько тестов, читающих из файла, можно будет вынести чтение в фикстуру.