Getting started with pytest Transcripts
Chapter: Configuration
Lecture: Configuration and other non-test files
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Welcome to chapter seven configuration files. We're going to talk about configuration files in this chapter.
0:07
Actually, we're going to talk about the files that you find in test suites that are not test files. So this of course does include the pytest ini file
0:14
which is the primary configuration file for pytest, but you can also use tox.ini or a pyproject.toml or a setup.cfg
0:24
These are alternate config files and you can also store your pytest Config in there. So if you already have one of these files in
0:31
your project, you can use that to store your pytest configuration. You can also add, even if you're using one of these,
0:37
you can add up pytest any if pytest at the same level of pytest finds a pytest any, it will use that instead of one of the others.
0:45
There's also conftest.py, we've used conftest to store fixtures. It can also store hook functions. We haven't talked about that in this course,
0:54
but that's one of the other uses also __init__.py. This file is used to avoid test name collision but there's some confusion over its use
1:04
for pytest within the questions online. But I want to cover the really the only reason why you need to use it
1:11
pytest.ini is the main configuration file that looks for, you can use other configuration files but in the pytest cards project for example,
1:21
pytest.ini is used and I just like to use keep it separate. You can well, like I said,
1:27
we'll show different ways. You can put it in other configuration files if you want There should only be one and it should be at the top of your project
1:35
This should be at most one conftest.py per directory and this one doesn't make sense to put it above in the project level.
1:44
It makes sense to put it in the tests, what it does is it stores your fixtures and hooks functions and applies to anything
1:53
below it. So in this example we've got three, we've got a tests level conftest. If fixtures there will apply to the whole project,
2:02
you can use those fixtures within the API or the CLI tests conftest.py, that's only in the API. You can't use those fixtures in the cli and vice versa.
2:12
So that's why there's options for multiple of them because you want to share between the test but you might not want to share them with all your tests
2:22
Another file we see in test suites is often a __init__ file? You can and I recommend having one within each directory which within each
2:34
subdirectory you don't need one at the top level test directory,
2:37
but the individual ones and this is so that you can have test names be identical in both sub-directories and we will show examples why that makes sense.