August 2018
Beginner
160 pages
4h 8m
English
Often, tests need a supporting file, for example a CSV file containing data about comedy series, as we saw in the last chapter. pytest-datadir allows you to save files alongside your tests and easily access them from the tests in a safe manner.
Suppose you have a file structure such as this:
tests/ test_series.py
In addition to this, you have a series.csv file that you need to access from tests defined in test_series.py.
With pytest-datadir installed, all you need to do is to create a directory with the name of the test file in the same directory and put the file there:
tests/ test_series/ series.csv test_series.py
The test_series directory and series.csv should be saved to your version-control system.
Now, tests in test_series.py ...
Read now
Unlock full access