diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2016-07-20 22:05:49 -0300 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2016-07-20 22:05:49 -0300 |
commit | 05f3422d7ca2ea75b5a5a1565a64642c847f6782 (patch) | |
tree | d7b17a98ac1dbbc16583b85b7472b1327033a4f6 /testing/test_monkeypatch.py | |
parent | 4f2bf965cbe9615cad5730c3d859a761d5ee46d3 (diff) | |
download | pytest-05f3422d7ca2ea75b5a5a1565a64642c847f6782.tar.gz |
Make monkeypatch invocation-scoped
Diffstat (limited to 'testing/test_monkeypatch.py')
-rw-r--r-- | testing/test_monkeypatch.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 7599be47f..0c152a8b6 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -328,4 +328,36 @@ def test_issue1338_name_resolving(): try: monkeypatch.delattr('requests.sessions.Session.request') finally: - monkeypatch.undo()
\ No newline at end of file + monkeypatch.undo() + + +def test_invocation_scoped_monkeypatch(testdir): + testdir.makeconftest(""" + import pytest + import sys + + @pytest.fixture(scope='module') + def stamp_sys(monkeypatch): + monkeypatch.setattr(sys, 'module_stamped', True, raising=False) + """) + testdir.makepyfile(test_inv_mokeypatch_1=""" + import sys + + def test_stamp_1(monkeypatch, stamp_sys): + assert sys.module_stamped + monkeypatch.setattr(sys, 'function_stamped', True, raising=False) + assert sys.function_stamped + + def test_stamp_2(monkeypatch): + assert sys.module_stamped + assert not hasattr(sys, 'function_stamped') + """) + testdir.makepyfile(test_inv_mokeypatch_2=""" + import sys + + def test_no_stamps(): + assert not hasattr(sys, 'module_stamped') + assert not hasattr(sys, 'function_stamped') + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines(['*3 passed*']) |