2 new commits in pytest: https://bitbucket.org/pytest-dev/pytest/commits/eea929322b9d/ Changeset: eea929322b9d User: The-Compiler Date: 2015-05-19 20:59:49+00:00 Summary: Fix monkeypatch.setenv with string and raising=False.
Fixes #746. Affected #: 2 files diff -r 6ee4b4d70a9b81f525c6fe46eab1b2018de6f4b0 -r eea929322b9dd2d0a19892ac29e2b80fc38617c5 _pytest/monkeypatch.py --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -27,7 +27,7 @@ -def derive_importpath(import_path): +def derive_importpath(import_path, raising): import pytest if not isinstance(import_path, _basestring) or "." not in import_path: raise TypeError("must be absolute import path string, not %r" % @@ -51,7 +51,8 @@ attr = rest.pop() obj = getattr(obj, attr) attr = rest[0] - getattr(obj, attr) + if raising: + getattr(obj, attr) except AttributeError: __tracebackhide__ = True pytest.fail("object %r has no attribute %r" % (obj, attr)) @@ -95,7 +96,7 @@ "setattr(target, value) with target being a dotted " "import string") value = name - name, target = derive_importpath(target) + name, target = derive_importpath(target, raising) oldval = getattr(target, name, notset) if raising and oldval is notset: @@ -124,7 +125,7 @@ raise TypeError("use delattr(target, name) or " "delattr(target) with target being a dotted " "import string") - name, target = derive_importpath(target) + name, target = derive_importpath(target, raising) if not hasattr(target, name): if raising: diff -r 6ee4b4d70a9b81f525c6fe46eab1b2018de6f4b0 -r eea929322b9dd2d0a19892ac29e2b80fc38617c5 testing/test_monkeypatch.py --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -62,6 +62,11 @@ pytest.raises(pytest.fail.Exception, lambda: monkeypatch.setattr("os.path.qweqwe", None)) + def test_unknown_attr_non_raising(self, monkeypatch): + # https://bitbucket.org/pytest-dev/pytest/issue/746/ + monkeypatch.setattr('os.path.qweqwe', 42, raising=False) + assert os.path.qweqwe == 42 + def test_delattr(self, monkeypatch): monkeypatch.delattr("os.path.abspath") assert not hasattr(os.path, "abspath") https://bitbucket.org/pytest-dev/pytest/commits/87208a0f0714/ Changeset: 87208a0f0714 User: hpk42 Date: 2015-06-03 21:37:26+00:00 Summary: Merged in The-Compiler/pytest (pull request #298) Fix monkeypatch.setenv with string and raising=False. Affected #: 2 files diff -r 84621bcbb544f251f2aac602c07b68797e70d51d -r 87208a0f071435507183f93c87043d6076cb2661 _pytest/monkeypatch.py --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -27,7 +27,7 @@ -def derive_importpath(import_path): +def derive_importpath(import_path, raising): import pytest if not isinstance(import_path, _basestring) or "." not in import_path: raise TypeError("must be absolute import path string, not %r" % @@ -51,7 +51,8 @@ attr = rest.pop() obj = getattr(obj, attr) attr = rest[0] - getattr(obj, attr) + if raising: + getattr(obj, attr) except AttributeError: __tracebackhide__ = True pytest.fail("object %r has no attribute %r" % (obj, attr)) @@ -95,7 +96,7 @@ "setattr(target, value) with target being a dotted " "import string") value = name - name, target = derive_importpath(target) + name, target = derive_importpath(target, raising) oldval = getattr(target, name, notset) if raising and oldval is notset: @@ -124,7 +125,7 @@ raise TypeError("use delattr(target, name) or " "delattr(target) with target being a dotted " "import string") - name, target = derive_importpath(target) + name, target = derive_importpath(target, raising) if not hasattr(target, name): if raising: diff -r 84621bcbb544f251f2aac602c07b68797e70d51d -r 87208a0f071435507183f93c87043d6076cb2661 testing/test_monkeypatch.py --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -62,6 +62,11 @@ pytest.raises(pytest.fail.Exception, lambda: monkeypatch.setattr("os.path.qweqwe", None)) + def test_unknown_attr_non_raising(self, monkeypatch): + # https://bitbucket.org/pytest-dev/pytest/issue/746/ + monkeypatch.setattr('os.path.qweqwe', 42, raising=False) + assert os.path.qweqwe == 42 + def test_delattr(self, monkeypatch): monkeypatch.delattr("os.path.abspath") assert not hasattr(os.path, "abspath") Repository URL: https://bitbucket.org/pytest-dev/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit