Skip to content

Commit

Permalink
One last bit of reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmavirus24 committed Jul 12, 2015
1 parent 3018c8f commit f743c04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
49 changes: 0 additions & 49 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,55 +82,6 @@ On the other hand, this will raise an exception:
r = s.post("https://httpbin.org/post",
data={"key": "value"})
pytest Integration
^^^^^^^^^^^^^^^^^^

.. versionadded:: 0.5.0

When you install Betamax, it now installs a `pytest`_ fixture by default. To
use it in your tests you need only follow the `instructions`_ on pytest's
documentation. To use the ``betamax_session`` fixture for an entire class of
tests you would do:

.. code-block:: python
# tests/test_http_integration.py
import pytest
@pytest.mark.usefixtures('betamax_session')
class TestMyHttpClient:
def test_get(self, betamax_session):
betamax_session.get('https://httpbin.org/get')
This will generate a cassette name for you, e.g.,
``tests.test_http_integration.TestMyHttpClient.test_get``. After running this
test you would have a cassette file stored in your cassette library directory
named ``tests.test_http_integration.TestMyHttpClient.test_get.json``. To use
this fixture at the module level, you need only do

.. code-block:: python
# tests/test_http_integration.py
import pytest
pytest.mark.usefixtures('betamax_session')
class TestMyHttpClient:
def test_get(self, betamax_session):
betamax_session.get('https://httpbin.org/get')
class TestMyOtherHttpClient:
def test_post(self, betamax_session):
betamax_session.post('https://httpbin.org/post')
.. _pytest: http://pytest.org/latest/
.. _instructions:
http://pytest.org/latest/fixture.html#using-fixtures-from-classes-modules-or-projects


.. _opinions:

Opinions at Work
Expand Down
52 changes: 49 additions & 3 deletions docs/usage_patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Usage Patterns

Below are suggested patterns for using Betamax efficiently.

Usage with py.test
------------------
Configuring Betamax in py.test's conftest.py
--------------------------------------------

Betamax and github3.py (the project which instigated the creation of Betamax)
both utilize py.test_ and its feature of configuring how the tests run with
Expand All @@ -28,6 +28,8 @@ check your cassettes into your version control system, then you can also add:
if not os.path.exists('tests/cassettes'):
os.makedirs('tests/cassettes')
An Example from github3.py
^^^^^^^^^^^^^^^^^^^^^^^^^^

You can configure other aspects of Betamax via the ``conftest.py`` file. For
example, in github3.py, I do the following:
Expand All @@ -51,7 +53,51 @@ to not try to record new cassettes or interactions. We also, want to make sure
we're authenticated when possible but that we do not leave our placeholder in
the cassettes when they're replayed.

py.test Integration
-------------------

.. versionadded:: 0.5.0

When you install Betamax, it now installs a `py.test`_ fixture by default. To
use it in your tests you need only follow the `instructions`_ on pytest's
documentation. To use the ``betamax_session`` fixture for an entire class of
tests you would do:

.. code-block:: python
# tests/test_http_integration.py
import pytest
@pytest.mark.usefixtures('betamax_session')
class TestMyHttpClient:
def test_get(self, betamax_session):
betamax_session.get('https://httpbin.org/get')
This will generate a cassette name for you, e.g.,
``tests.test_http_integration.TestMyHttpClient.test_get``. After running this
test you would have a cassette file stored in your cassette library directory
named ``tests.test_http_integration.TestMyHttpClient.test_get.json``. To use
this fixture at the module level, you need only do

.. code-block:: python
# tests/test_http_integration.py
import pytest
pytest.mark.usefixtures('betamax_session')
class TestMyHttpClient:
def test_get(self, betamax_session):
betamax_session.get('https://httpbin.org/get')
class TestMyOtherHttpClient:
def test_post(self, betamax_session):
betamax_session.post('https://httpbin.org/post')
.. _py.test: http://pytest.org/latest/
.. _TravisCI: https://travis-ci.org/
.. [#] http://pytest.org/latest/plugins.html
.. _py.test: http://pytest.org/latest/
.. _instructions:
http://pytest.org/latest/fixture.html#using-fixtures-from-classes-modules-or-projects

0 comments on commit f743c04

Please sign in to comment.