-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
During the previous tutorial, folks found it hard to navigate between the steps because the file names did not indicate the order the steps were in. Updated mock tests to make use of pytest-mock, which is the recommended way of mixing mocking and pytest. Made step 5 and 7 consistent with the rest of the steps. Added links to solutions, looks like step 7 doesn't have any solutions for folks to refer to. Also added a couple pictures to the steps to make them a bit more fun.
- Loading branch information
christie
committed
Jan 31, 2016
1 parent
cf49b38
commit 3db2da1
Showing
20 changed files
with
98 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Testing Classes with Fixtures | ||
|
||
This assumes you have setup your environment as described in [run_tests.md] | ||
and that you are in your virtualenv. | ||
|
||
![cattery](../pics/cattery.png) | ||
|
||
If you get stuck, [take a peek at the solution](https://github.com/keeppythonweird/catinabox/blob/solutions/tests/test_cattery.py). | ||
|
||
1. Refactor the Cattery tests in [test_cattery.py](../tests/test_cattery.py) | ||
to use a py.test fixture. | ||
|
||
```python | ||
@pytest.fixture | ||
def cattery_client(): | ||
... | ||
|
||
def test__add_cats__succeeds(cattery_client): | ||
... | ||
``` | ||
|
||
2. Try adding a `scope` argument to `pytest.fixture`. What happens when | ||
you try setting it to `scope`, `session`, or `module`? | ||
|
||
```python | ||
@pytest.fixture(scope='session') | ||
def cattery_client(): | ||
... | ||
``` | ||
|
||
3. When you are done, run your tests: | ||
|
||
```bash | ||
(catpy)user@host:~/catinabox$ python setup.py test | ||
``` | ||
|
||
4. When the tests run successfully, push them to your pull request: | ||
|
||
```bash | ||
(catpy)user@host:~/catinabox$ git commit -a | ||
(catpy)user@host:~/catinabox$ git push origin master | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
mccabe==0.3.1 | ||
mock | ||
pyflakes==1.0.0 | ||
pytest-cov==2.1.0 | ||
pytest-flakes==1.0.1 | ||
pytest-mccabe==0.1 | ||
pytest-pep8==1.0.6 | ||
pytest-mock==0.10.1 | ||
pytest==2.8.2 | ||
six==1.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
# import pytest | ||
import six | ||
import time | ||
# import time | ||
|
||
# from catinabox import catactivities | ||
|
||
if six.PY2: | ||
import mock | ||
else: | ||
from unittest import mock | ||
|
||
|
||
@mock.patch.object(time, "sleep", autospec=True) | ||
def test__cat_nap__satisfying_nap(sleep): | ||
def test__cat_nap__satisfying_nap(mocker): | ||
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True) | ||
assert True | ||
|
||
|
||
@mock.patch.object(time, "sleep", autospec=True) | ||
def test__cat_nap__not_satisfying(sleep): | ||
def test__cat_nap__not_satisfying(mocker): | ||
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True) | ||
assert True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters