Skip to content

Instantly share code, notes, and snippets.

@romuald
Created February 19, 2021 09:48
Show Gist options
  • Save romuald/d77a7f986b96597d4e81142d4f1248dd to your computer and use it in GitHub Desktop.
Save romuald/d77a7f986b96597d4e81142d4f1248dd to your computer and use it in GitHub Desktop.
Automatically sets a global "pp" variable alias to pprint in all tests
import pytest
import pprint
import unittest.mock
@pytest.fixture(autouse=True, scope='function')
def auto_pprint(request):
"""
Automatically sets a global "pp" variable alias to pprint in all tests
"""
module = request.node.module
with unittest.mock.patch.object(module, 'pp', pprint.pprint, create=True):
yield
# ...
def test_evil_patch():
pp({'foo': 'bar'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment