wal
.
sh
Research
Events
Current
home
>
research
>
flashcards
>
python-pytest-drill
· Apr 18, 2026
Mastering pytest: A Comprehensive Guide
Mastering pytest: A Comprehensive Guide
Table of Contents
1. Pytest Drill
1.1. Running Tests
1.1.1. How do I run all tests in the current directory?
drill
python_pytest
1.1.1.1. Answer
1.1.2. How do I run all tests in a specific file?
drill
python_pytest
1.1.2.1. Answer
1.1.3. How do I run a specific test function?
drill
python_pytest
1.1.3.1. Answer
1.1.4. How do I run all tests with a specific marker?
drill
python_pytest
1.1.4.1. Answer
1.2. Fixtures
1.2.1. What is a fixture in pytest?
drill
python_pytest
1.2.1.1. Answer
1.2.2. How do I define a fixture in pytest?
drill
python_pytest
1.2.2.1. Answer
1.2.3. How do I use a fixture in a test function?
drill
python_pytest
1.2.3.1. Answer
1.3. Assertions
1.3.1. How do I make an assertion in pytest?
drill
python_pytest
1.3.1.1. Answer
1.3.2. What happens if an assertion fails in pytest?
drill
python_pytest
1.3.2.1. Answer
1.4. Markers
1.4.1. What is a marker in pytest?
drill
python_pytest
1.4.1.1. Answer
1.4.2. How do I define a marker in pytest?
drill
python_pytest
1.4.2.1. Answer
1.4.3. How do I run all tests with a specific marker?
drill
python_pytest
1.4.3.1. Answer
1.5. Skipping Tests
1.5.1. How do I skip a test in pytest?
drill
python_pytest
1.5.1.1. Answer
1.5.2. How do I skip a test based on a condition?
drill
python_pytest
1.5.2.1. Answer
1.6. Xfail
1.6.1. What is xfail in pytest?
drill
python_pytest
1.6.1.1. Answer
1.6.2. How do I mark a test as xfail in pytest?
drill
python_pytest
1.6.2.1. Answer
1.7. Parametrize
1.7.1. What is parametrize in pytest?
drill
python_pytest
1.7.1.1. Answer
1.7.2. How do I parametrize a test function in pytest?
drill
python_pytest
1.7.2.1. Answer
1.8. Plugins
1.8.1. What is a plugin in pytest?
drill
python_pytest
1.8.1.1. Answer
1.8.2. How do I install a pytest plugin?
drill
python_pytest
1.8.2.1. Answer
1.
Pytest Drill
1.1.
Running Tests
1.1.1.
How do I run all tests in the current directory?
drill
python_pytest
1.1.1.1.
Answer
pytest
1.1.2.
How do I run all tests in a specific file?
drill
python_pytest
1.1.2.1.
Answer
pytest <filename>
1.1.3.
How do I run a specific test function?
drill
python_pytest
1.1.3.1.
Answer
pytest <filename>::<function_name>
1.1.4.
How do I run all tests with a specific marker?
drill
python_pytest
1.1.4.1.
Answer
pytest -m <marker_name>
1.2.
Fixtures
1.2.1.
What is a fixture in pytest?
drill
python_pytest
1.2.1.1.
Answer
A setup function that provides a fixed baseline so that tests execute reliably and consistently.
1.2.2.
How do I define a fixture in pytest?
drill
python_pytest
1.2.2.1.
Answer
Using the `@pytest.fixture` decorator.
1.2.3.
How do I use a fixture in a test function?
drill
python_pytest
1.2.3.1.
Answer
By including the fixture name as an argument in the test function.
1.3.
Assertions
1.3.1.
How do I make an assertion in pytest?
drill
python_pytest
1.3.1.1.
Answer
Using the `assert` statement.
1.3.2.
What happens if an assertion fails in pytest?
drill
python_pytest
1.3.2.1.
Answer
The test fails and pytest displays an error message.
1.4.
Markers
1.4.1.
What is a marker in pytest?
drill
python_pytest
1.4.1.1.
Answer
A way to categorize tests based on certain characteristics.
1.4.2.
How do I define a marker in pytest?
drill
python_pytest
1.4.2.1.
Answer
Using the `@pytest.mark` decorator.
1.4.3.
How do I run all tests with a specific marker?
drill
python_pytest
1.4.3.1.
Answer
pytest -m <marker_name>
1.5.
Skipping Tests
1.5.1.
How do I skip a test in pytest?
drill
python_pytest
1.5.1.1.
Answer
Using the `@pytest.mark.skip` decorator.
1.5.2.
How do I skip a test based on a condition?
drill
python_pytest
1.5.2.1.
Answer
Using the `@pytest.mark.skipif` decorator.
1.6.
Xfail
1.6.1.
What is xfail in pytest?
drill
python_pytest
1.6.1.1.
Answer
A way to mark a test as expected to fail.
1.6.2.
How do I mark a test as xfail in pytest?
drill
python_pytest
1.6.2.1.
Answer
Using the `@pytest.mark.xfail` decorator.
1.7.
Parametrize
1.7.1.
What is parametrize in pytest?
drill
python_pytest
1.7.1.1.
Answer
A way to run the same test function with different inputs.
1.7.2.
How do I parametrize a test function in pytest?
drill
python_pytest
1.7.2.1.
Answer
Using the `@pytest.mark.parametrize` decorator.
1.8.
Plugins
1.8.1.
What is a plugin in pytest?
drill
python_pytest
1.8.1.1.
Answer
A way to extend the functionality of pytest.
1.8.2.
How do I install a pytest plugin?
drill
python_pytest
1.8.2.1.
Answer
Using pip, e.g. `pip install pytest-<plugin_name>`.
← prev
next →