Modern Python Projects Transcripts
Chapter: Testing code
Lecture: Configuration file
0:00 Instead of passing arguments each time you run pytest command,
0:03 you can customize them by creating a configuration file.
0:06 pytest can actually accept different configuration.
0:09 File for months. You can use pytest.ini.
0:12 You can use pyproject, but this requires version 6.0 of pytest.
0:17 You can use tox.ini and you can also use setup.cfg
0:20 I will show you how to use pyproject.toml.
0:23 Why this format? Well, that's because it's the same format that tools like pipenv
0:28 and poetry use. So chances are that if you're using poetry or pipenv and
0:32 you already have this toml file,
0:36 plus there are some peps like pep-518 that recommends to use it instead of the
0:41 old setup.ui.
0:42 So I think this is the format that's going to be widely adopted in the python
0:46 community in the future. So here is the example pyProject.toml file that
0:51 I got from the pytest documentation. To get this syntax highlighting,
0:55 I had to go to the extension marketplace and installed Better TOML extension and then I
1:01 Choose TOML language here. Here we specify that we want to use at least version 6.0
1:07 of pytest, although if we're using an older version,
1:11 it won't even recognize this toml config file because it's supported from version 6.0.
1:16 But anyway, it's good to specify the minimal version,
1:19 especially if we depend on some features that were added in the specific version of pytest
1:23 Next we configure additional options that pytest is run with.
1:29 That's probably something that you will be using most often instead of having to remember a
1:33 bunch of flags and arguments. to pytest.
1:36 We can specify them here. So what we do here is first,
1:40 we're telling pytest that we want to get a nice summary of how many test failed
1:45 succeeded or how many warnings we got with the -a parameter.
1:50 Next, we want to make the output a bit less for both,
1:53 with -q parameter. And finally we tell it to skip all tests marked as
1:59 slow. We also have this Test paths option,
2:02 which specifies which folders we are using to store our tests.
2:07 In this case, pytest would look for project inside the test directory,but also inside the integration directory.