Created
February 19, 2021 09:48
-
-
Save romuald/d77a7f986b96597d4e81142d4f1248dd to your computer and use it in GitHub Desktop.
Automatically sets a global "pp" variable alias to pprint in all tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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