Testing the export function

In the same test module, I have defined another class that represents a test suite for the export function. Here it is:

# tests/test_api.pyclass TestExport:    @pytest.fixture    def csv_file(self, tmpdir):        yield tmpdir.join("out.csv")    @pytest.fixture    def existing_file(self, tmpdir):        existing = tmpdir.join('existing.csv')        existing.write('Please leave me alone...')        yield existing

Let's start understanding the fixtures. We have defined them at class-level this time, which means they will be alive only for as long as the tests in the class are running. We don't need these fixtures outside of this class, so it doesn't make sense to declare them at a module level like we've done with the user ones.

So, we need two files. ...

Get Learn Web Development with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.