How to use the patchy.temp_patch function in patchy

To help you get started, we’ve selected a few patchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adamchainz / patchy / tests / test_temp_patch.py View on Github external
    @patchy.temp_patch(sample, patch_text)
    def decorated():
        assert sample() == 7890
github adamchainz / patchy / tests / test_temp_patch.py View on Github external
def test_context_manager():
    def sample():
        return 1234

    patch_text = """\
        @@ -1,2 +1,2 @@
         def sample():
        -    return 1234
        +    return 5678
        """

    assert sample() == 1234
    with patchy.temp_patch(sample, patch_text):
        assert sample() == 5678
    assert sample() == 1234
github adamchainz / patchy / tests / test_temp_patch.py View on Github external
"""\
        class Foo(object):
            def sample(self):
                return 1
        """
        )
    )
    sys.path.insert(0, six.text_type(tmpdir))
    patch_text = """\
        @@ -2,2 +2,2 @@
        -    return 1
        +    return 2
        """

    try:
        with patchy.temp_patch("tmp_by_path_pkg.mod.Foo.sample", patch_text):
            from tmp_by_path_pkg.mod import Foo

            assert Foo().sample() == 2
    finally:
        sys.path.pop(0)

    assert Foo().sample() == 1