Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@patchy.temp_patch(sample, patch_text)
def decorated():
assert sample() == 7890
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
"""\
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