<s> try : <EOL> import unittest . mock as mock <EOL> except ImportError : <EOL> import mock <EOL> import pytest <EOL> import unittest <EOL> import requests <EOL> import betamax <EOL> from betamax . fixtures import pytest as pytest_fixture <EOL> from betamax . fixtures import unittest as unittest_fixture <EOL> class TestPyTestFixture ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mocked_betamax = mock . MagicMock ( ) <EOL> self . patched_betamax = mock . patch . object ( <EOL> betamax . recorder , '<STR_LIT>' , return_value = self . mocked_betamax ) <EOL> self . patched_betamax . start ( ) <EOL> def tearDown ( self ) : <EOL> self . patched_betamax . stop ( ) <EOL> def test_adds_stop_as_a_finalizer ( self ) : <EOL> request = mock . MagicMock ( ) <EOL> request . cls = request . module = None <EOL> request . function . __name__ = '<STR_LIT:test>' <EOL> pytest_fixture . betamax_recorder ( request ) <EOL> assert request . addfinalizer . called is True <EOL> request . addfinalizer . assert_called_once_with ( self . mocked_betamax . stop ) <EOL> def test_auto_starts_the_recorder ( self ) : <EOL> request = mock . MagicMock ( ) <EOL> request . cls = request . module = None <EOL> request . function . __name__ = '<STR_LIT:test>' <EOL> pytest_fixture . betamax_recorder ( request ) <EOL> self . mocked_betamax . start . assert_called_once_with ( ) <EOL> class FakeBetamaxTestCase ( unittest_fixture . BetamaxTestCase ) : <EOL> def test_fake ( self ) : <EOL> pass <EOL> class TestUnittestFixture ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mocked_betamax = mock . MagicMock ( ) <EOL> self . patched_betamax = mock . patch . object ( <EOL> betamax . recorder , '<STR_LIT>' , return_value = self . mocked_betamax ) <EOL> self . betamax = self . patched_betamax . start ( ) <EOL> self . fixture = FakeBetamaxTestCase ( methodName = '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> self . patched_betamax . stop ( ) <EOL> def test_setUp ( self ) : <EOL> self . fixture . setUp ( ) <EOL> self . mocked_betamax . use_cassette . assert_called_once_with ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . mocked_betamax . start . assert_called_once_with ( ) <EOL> def test_setUp_rejects_arbitrary_session_classes ( self ) : <EOL> self . fixture . SESSION_CLASS = object <EOL> with pytest . raises ( AssertionError ) : <EOL> self . fixture . setUp ( ) <EOL> def test_setUp_accepts_session_subclasses ( self ) : <EOL> class TestSession ( requests . Session ) : <EOL> pass <EOL> self . fixture . SESSION_CLASS = TestSession <EOL> self . fixture . setUp ( ) <EOL> assert self . betamax . called is True <EOL> call_kwargs = self . betamax . call_args [ - <NUM_LIT:1> ] <EOL> assert isinstance ( call_kwargs [ '<STR_LIT>' ] , TestSession ) <EOL> def test_tearDown_calls_stop ( self ) : <EOL> recorder = mock . Mock ( ) <EOL> self . fixture . recorder = recorder <EOL> self . fixture . tearDown ( ) <EOL> recorder . stop . assert_called_once_with ( ) </s>
