diff options
author | Anthony Sottile <asottile@umich.edu> | 2018-08-23 09:06:17 -0700 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2018-08-23 09:06:17 -0700 |
commit | 85482d575e6a868c829fe6f9b9d9fe3a6cab4a53 (patch) | |
tree | 54dd3579c46e42cd8f80ca6159efc904c14f516e /testing/code | |
parent | 6f7365509dbf3f734c160e9fe94dfc99f6b0f6fd (diff) | |
download | pytest-85482d575e6a868c829fe6f9b9d9fe3a6cab4a53.tar.gz |
Replace Source with dedent where possible
Diffstat (limited to 'testing/code')
-rw-r--r-- | testing/code/test_code.py | 9 | ||||
-rw-r--r-- | testing/code/test_excinfo.py | 8 |
2 files changed, 7 insertions, 10 deletions
diff --git a/testing/code/test_code.py b/testing/code/test_code.py index 27916d64f..f7a8a4dbd 100644 --- a/testing/code/test_code.py +++ b/testing/code/test_code.py @@ -4,6 +4,7 @@ import sys import _pytest._code import pytest +import mock from test_excinfo import TWMock from six import text_type @@ -67,12 +68,8 @@ def test_getstatement_empty_fullsource(): f = func() f = _pytest._code.Frame(f) - prop = f.code.__class__.fullsource - try: - f.code.__class__.fullsource = None - assert f.statement == _pytest._code.Source("") - finally: - f.code.__class__.fullsource = prop + with mock.patch.object(f.code.__class__, "fullsource", None): + assert f.statement == "" def test_code_from_func(): diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index f8bf25b68..52cad6a3e 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -149,7 +149,7 @@ class TestTraceback_f_g_h(object): except somenoname: pass xyz() - """ + """ ) try: exec(source.compile()) @@ -426,7 +426,7 @@ class TestFormattedExcinfo(object): @pytest.fixture def importasmod(self, request): def importasmod(source): - source = _pytest._code.Source(source) + source = textwrap.dedent(source) tmpdir = request.getfixturevalue("tmpdir") modpath = tmpdir.join("mod.py") tmpdir.ensure("__init__.py") @@ -450,10 +450,10 @@ class TestFormattedExcinfo(object): def test_repr_source(self): pr = FormattedExcinfo() source = _pytest._code.Source( - """ + """\ def f(x): pass - """ + """ ).strip() pr.flow_marker = "|" lines = pr.get_source(source, 0) |