Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.42 KB

5-classes.md

File metadata and controls

52 lines (36 loc) · 1.42 KB

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

If you get stuck, take a peek at the solution.

  1. Refactor the Cattery tests in test_cattery.py to use a py.test fixture.

    @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 session or module?

    @pytest.fixture(scope='session')
    def cattery_client():
        ...
  3. When you are done, run your tests:

(catpy)user@host:~/catinabox$ python setup.py test
  1. When the tests run successfully, push them to your pull request:
(catpy)user@host:~/catinabox$ git commit -a
(catpy)user@host:~/catinabox$ git push origin master

BONUS

Take a look at the builtin fixtures that pytest provides. Are there any that would be useful for these, or any of the previous tests you have written so far? Can you think of some ways you might use fixtures when writing tests for your other projects?

We'd love to discuss this with you!