Справочные материалы
- Pytest with Eric – подборка отличных туториалов по всем вопросам, связанным с написанием тестов под
pytest. - Серия статей о тестировании (в т.ч., с
pytest) в блоге Bite Code!:- Testing with Python (part 1): the basics
- Testing with Python (part 2): moving to pytest
- Testing with Python (part 3): pytest setup
- Testing with Python (part 4): why and what to test?
- Testing with Python (part 5): the different types of tests
- Testing with Python (part 6): Fake it…
- Testing with Python (part 7): …until you make it
- Testing with Python (part 8): purity test
- Testing with Python (part 9): the extra mile
- Developing and Testing an Asynchronous API with FastAPI and Pytest – TestDriven.io
Examples
- FastAPI Project Setup: The Ultimate Guide with Async Postgres, SQLModel, Pytest, & Docker
- Async tests with FastAPI and Postgres
Configuration
Configure#pytest#testing using pyproject.toml:
[tool.pytest.ini_options] # mandatory section name
addopts = "-s --no-header --no-summary" # force cmd flags
testpaths = [ # what directories contain tests
"tests",
]
pythonpath = [ # what to add to the python path
"."
]Useful Flags
-x: stop a first failure.--pdb: start the Python debugger on failure.-k <filter>: only discover tests that match the filter.--ff: start with tests that failed in the previous run.--nf: start with new files.--sw: start from where it stopped the previous run.--no-header/--no-summary: remove the big blobs of texts in the output.--verbosity=x: from 0 to 3 levels of output granularity.-m: прогнать только тесты с определенной меткой, которая устанавливается декоратором@pytest.mark.new, гдеnew- имя метки.
📂 Frameworks | Последнее изменение: 31.08.2024 11:12