Modern Python Projects Transcripts
Chapter: Testing code
Lecture: Configuration file

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

Talk Python's Mastodon Michael Kennedy's Mastodon