from __future__ import absolute_import

import pytest
import os
import mock
import json

import app.mapping


with open(os.path.join(os.path.dirname(__file__), 'fixtures/mappings/services.json')) as f:
    _services_mapping_definition = json.load(f)


@pytest.fixture(scope="function")
def services_mapping():
    """Provide a services mapping fixture, and patch it into the global singleton getter."""

    mock_services_mapping_getter_patch = mock.patch('app.mapping.get_services_mapping')
    mock_services_mapping_getter = mock_services_mapping_getter_patch.start()
    mock_services_mapping_getter.return_value = app.mapping.Mapping(_services_mapping_definition, 'services')

    yield mock_services_mapping_getter.return_value

    mock_services_mapping_getter_patch.stop()

@@ -405,44 +405,12 @@
     
-mock_services_mapping_getter_patch =
+with
  moc
@@ -452,20 +452,19 @@
 apping')
-%0A   
+ as
  mock_se
@@ -488,54 +488,14 @@
 tter
- = mock_services_mapping_getter_patch.start()%0A
+:%0A    
     
@@ -600,17 +600,20 @@
 vices')%0A
-%0A
+    
     yiel
@@ -660,51 +660,4 @@
 lue%0A
-%0A    mock_services_mapping_getter_patch.stop()%0A

Use with block to start/stop the patch context manager.