pytest-power
Adds a number of shorthands for fixtures and other helpers for easier testing:
- patch.object
- patch.init
- patch.many
- patch.everything
You can instal pytest-power with pip:
pip install pytest-power
Usage
patch.object
A shorthand for pytest-mock's mocker.patch.object
from myapp import App
def test_app_run(patch):
patch.object(App, 'run')
App.run()
assert App.run.call_count == 1
You can pass keywords arguments as usual:
from myapp import App
def test_app_run(patch):
patch.object(App, 'run', return_value='running')
assert App.run() == 'running'
patch.init
Makes patching __init__ a bit simpler:
from myapp import App
def test_app_init(patch):
patch.init(App)
app = App()
assert isinstance(app, App)
Instances patched in this way do not have properties that are set in __init__,
so they have to be set again by hand.
Keyword arguments are passed to underlying patch.object, and autospec is
enabled by default.
Multiple classes can be passed too:
patch.init(App, Cli)
patch.many
A shorthand to patch many properties of the same object:
from myapp import App
def test_app_run_called_by_run(patch):
patch.many(App, ['run', 'called_by_run'])
App.run()
assert App.called_by_run.call_count == 1
Keyword arguments are again passed to underlying patch.object, and autospec
is enabled by default.
patch.everything
A shorthand to patch every non-magic property. Useful when patch.many gets too long!
from myapp import App
def test_app_run_called_by_run(patch):
patch.everything(App)
App.run()
assert App.called_by_run.call_count == 1
Supports forcing the exclusion of properties:
from myapp import App
def test_app_run(patch, excludes=['run']):
patch.everything(App)
App.run()
assert App.called_by_run.call_count == 1
And forcing the inclusion of properties:
from myapp import App
def test_app_run(patch, includes=['__private__']):
patch.everything(App)
App.run()
assert App.__private__.call_count == 1
Release files for pytest-power 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-power-1.0.1.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_power-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / pytest-power-1.0.1.tar.gz
| Download URL | pytest-power-1.0.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5123622ccc00d32417f63c8a11e575d99633be61ed6a2005ba4bf9b33216004
|
|
BLAKE2b-256 checksum How to use checksums |
6cb03767ae6e990dd0562e8e091223f289834bf9208864bad96c2fbd1b7aff42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Darwin/19.6.0
|
Release files / pytest_power-1.0.1-py3-none-any.whl
| Download URL | pytest_power-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3f05a67b715208e999f3ea5394659af3981e20c72f226f5fdc3898f5de42a94
|
|
BLAKE2b-256 checksum How to use checksums |
741a8ccc6e844a8877e89d944585ad00683a506b6022c9cd58cc608e03b2f296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Darwin/19.6.0
|