Pytest Configuration
Explore how to customize pytest through command-line options and configuration files like pytest.ini and conftest.py. Understand options for verbosity, test selection, warning filters, and logging setup to tailor pytest for your testing needs.
Introduction
Pytest configuration is a powerful tool that allows users to customize the behavior of pytest. With configuration files, environment variables, custom fixtures, and plugins, users can modify various aspects of pytest to fit their specific needs. In this lesson, we will deep dive into pytest command-line options and configuration files.
Command-line options
Pytest provides many command-line options that can be used to customize the behavior of pytest. These options are specified when running pytest commands, like so:
pytest [options] [file_or_directory]
Some of the most commonly used command-line options include the following:
-v: This increases verbosity and prints more detailed output.-s: This disables the capturing ofstdout/stderr. It’s useful for debugging.-k: This selects tests based on their name.-m: This selects tests based on their markers.-x: This stops the test session after the first test failure.--maxfail=num: This exits after a specified number of test failures.--capture: This specifies how to capture output from the tests. The default value isfd, which means that output is captured to a file descriptor. Other options includeno, which disables output ...