diff --git a/tests/conftest.py b/tests/conftest.py index 5b307ad..c183eee 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,33 +48,3 @@ def twenty_cls_tests(): for i in range(20): code.append("\tdef test_b{0}(self): self.assertTrue\n".format(str(i).zfill(2))) return "".join(code) - - -def _deindent_source(source): - """ - A minimal replacement for py.code.Source to deindent inlined test code. - Looks for the first non-empty line to determine deindent offset, doesn't - attempt to understand the code, line continuations, etc. - """ - lines = source.splitlines() - for line in lines: - stripped = line.lstrip() - if stripped: - offset = len(line) - len(stripped) - break - else: - offset = 0 - - output_lines = [] - for line in lines: - output_lines.append(line[offset:]) - - return "\n".join(output_lines) - - -@pytest.fixture -def deindent_source(): - """ - Returns a helper function to deindent inlined source code. - """ - return _deindent_source diff --git a/tests/test_actual_test_runs.py b/tests/test_actual_test_runs.py index 04bec22..cbbc5a2 100644 --- a/tests/test_actual_test_runs.py +++ b/tests/test_actual_test_runs.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- import collections import re +import textwrap import pytest @pytest.fixture -def tmp_tree_of_tests(testdir, deindent_source): +def tmp_tree_of_tests(testdir): """ Creates a directory structure: tmpdir/ @@ -24,7 +25,7 @@ def tmp_tree_of_tests(testdir, deindent_source): sup = testdir.mkpydir("shallow_tests") sup.join("test_a.py").write( - deindent_source(""" + textwrap.dedent(""" def test_a1(): assert False def test_a2(): @@ -35,7 +36,7 @@ def test_a3(): ) sup.join("test_ax.py").write( - deindent_source(""" + textwrap.dedent(""" def test_ax1(): assert True def test_ax2(): @@ -48,7 +49,7 @@ def test_ax3(): sub = testdir.mkpydir("shallow_tests/deep_tests") sub.join("test_b.py").write( - deindent_source(""" + textwrap.dedent(""" def test_b1(): assert True def test_b2(): @@ -59,14 +60,14 @@ def test_b3(): ) sub.join("test_c.py").write( - deindent_source(""" + textwrap.dedent(""" def test_c1(): assert True """) ) sub.join("test_d.py").write( - deindent_source(""" + textwrap.dedent(""" def test_d1(): assert True def test_d2(): @@ -75,7 +76,7 @@ def test_d2(): ) sub.join("test_e.py").write( - deindent_source(""" + textwrap.dedent(""" from unittest import TestCase class EeTest(TestCase): def test_ee1(self): diff --git a/tests/test_doctests.py b/tests/test_doctests.py index 90f6b02..443b9b7 100644 --- a/tests/test_doctests.py +++ b/tests/test_doctests.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- +import textwrap + import pytest @pytest.fixture -def tmp_tree_of_tests(testdir, deindent_source): +def tmp_tree_of_tests(testdir): """ Creates a directory structure: tmpdir/ @@ -15,7 +17,7 @@ def tmp_tree_of_tests(testdir, deindent_source): utils_package.join("__init__.py").write("") utils_package.join("foo.py").write( - deindent_source(''' + textwrap.dedent(''' def add(a, b): """ >>> add(1, 1)