Skip to content

Commit

Permalink
add proper examples to pytest-testslide/README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
deathowl committed Dec 31, 2020
1 parent 9b09d7e commit 1cf6e64
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pytest-testslide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@ pip install pytest-testslide

In your test file:
```
import pytest
from pytest_testslide import testslide
from testslide import StrictMock # if you wish to use StrictMock
from testslide import matchers # if you wish to use Rspec style argument matchers
.....
testslide.mock_callable # to use mock_callable
testslide.mock_async_callable # to use mock_async_callable
testslide.mock_constructor # to use mock_constructor
testslide.patch_attribute # to use patch_attribute
def test_mock_callable_patching_works(testslide):
testslide.mock_callable(time, "sleep").to_raise(RuntimeError("Mocked!")) #mock_callable
with pytest.raises(RuntimeError):
time.sleep()
@pytest.mark.asyncio
async def test_mock_async_callable_patching_works(testslide):
testslide.mock_async_callable(sample_module.ParentTarget, "async_static_method").to_raise(RuntimeError("Mocked!")) #mock_async_callable
with pytest.raises(RuntimeError):
await sample_module.ParentTarget.async_static_method("a", "b")
def test_mock_constructor_patching_works(testslide):
testslide.mock_constructor(sample_module, "ParentTarget").to_raise(RuntimeError("Mocked!")) #mock_constructor
with pytest.raises(RuntimeError):
sample_module.ParentTarget()
def test_patch_attribute_patching_works(testslide):
testslide.patch_attribute(sample_module.SomeClass, "attribute", "patched") #patch_attribute
assert sample_module.SomeClass.attribute == "patched"
```

0 comments on commit 1cf6e64

Please sign in to comment.