Python Pytest
Write fast, parametrized tests with fixtures and markers.
- pytest
- parametrize
- fixture
- conftest
- python testing
Python Pytest
Write fast, parametrized tests with fixtures and markers.
Commands
| Command | What it does |
|---|---|
pytest -q | Run the suite quietly |
pytest -k "search and not slow" | Select by name expression |
pytest --maxfail=1 -x | Stop at first failure |
@pytest.mark.parametrize("x,y", [...]) | One test, many cases |
@pytest.fixture | Reusable setup/teardown |
Example
import pytest
@pytest.mark.parametrize("a,b,expected", [(1,2,3),(0,0,0)])
def test_add(a, b, expected):
assert a + b == expected
FAQ
unittest vs pytest?
pytest runs unittest cases too, but needs far less boilerplate; fixtures beat setUp/tearDown for composition.
Where do fixtures live?
conftest.py per directory — auto-discovered, no imports needed.
よくある質問
unittest vs pytest?
pytest runs unittest cases too, but needs far less boilerplate; fixtures beat setUp/tearDown for composition.
Where do fixtures live?
conftest.py per directory — auto-discovered, no imports needed.
Python
Python Venv and Environments
Isolate dependencies per project with venv and pinned requirements.
Python Pip Essentials
Install, upgrade, and audit packages with pip like a pro.
Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
Python Strings
Slice, split, join, and format text efficiently.