mirror of
https://github.com/vinta/awesome-python.git
synced 2026-11-10 01:34:28 -06:00
docs: add pytest-benchmark to Testing intro
The intro did not mention a README entry added after it was written, so readers got no advice on it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ How to choose:
|
||||
- Testing across Python versions: tox, or Nox to configure it in Python
|
||||
- WebDriver tests on remote machines: Selenium, or SeleniumBase with waits and reports built in
|
||||
- Load tests written as Python code: Locust
|
||||
- Timing a function and catching slowdowns: pytest-benchmark
|
||||
- API tests generated from an OpenAPI or GraphQL schema: Schemathesis
|
||||
- Replacing objects in a test: unittest.mock, or time-machine for the clock
|
||||
- Faking HTTP calls: responses for Requests, RESPX for HTTPX, VCR.py to record real traffic
|
||||
@@ -30,6 +31,8 @@ Selenium drives browsers through WebDriver, a W3C standard, and [Selenium Grid](
|
||||
|
||||
A Locust test is [a Python program](https://docs.locust.io/en/stable/quickstart.html): an `HttpUser` class whose tasks make requests, so complex user flows are just code.
|
||||
|
||||
pytest-benchmark runs microbenchmarks as pytest tests. A test requests [the `benchmark` fixture](https://pytest-benchmark.readthedocs.io/en/latest/) and calls it with the function to measure and its arguments. The plugin calibrates the runs on its own and returns the function's result, so the test can still assert it's correct. Save a run, then [compare later runs against it](https://pytest-benchmark.readthedocs.io/en/latest/comparing.html), and add `--benchmark-compare-fail` to fail the suite when a test slows down past a threshold you set.
|
||||
|
||||
Schemathesis reads your OpenAPI or GraphQL schema and generates property-based tests from it, with no per-endpoint tests to maintain. Its FAQ [recommends the CLI](https://schemathesis.readthedocs.io/en/stable/faq/#how-should-i-run-schemathesis) for most users, with a pytest integration for existing suites.
|
||||
|
||||
With unittest.mock, [patch a name where it's looked up](https://docs.python.org/3/library/unittest.mock.html#where-to-patch), which isn't always where it's defined. [Autospec](https://docs.python.org/3/library/unittest.mock.html#autospeccing) your mocks, so a test fails when your code calls an API the real object lacks. For the clock, time-machine [mocks time functions everywhere they're referenced](https://time-machine.readthedocs.io/en/latest/comparison.html), where a patch only reaches the import location it targets.
|
||||
|
||||
Reference in New Issue
Block a user