pytest plugin with powerful fixtures
Project description
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.
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_power-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2ff82bc04a5ae54c5005da463ea6ff94ff7a36aa89d86aac44653465a9a7438 |
|
MD5 | 7a2d18b10c5856e5b4e10a0fd08b7b26 |
|
BLAKE2b-256 | 91acc72f79f25ef61e7368f769515032733d07610590020595af52842d2d21a0 |