Merge pull request #3864 from asottile/source_to_dedent

Replace Source with dedent where possible
This commit is contained in:
Anthony Sottile 2018-08-23 10:45:11 -07:00 committed by GitHub
commit 52fa8c98bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 562 additions and 568 deletions

View File

@ -2,11 +2,11 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import os import os
import sys import sys
import textwrap
import types import types
import six import six
import _pytest._code
import py import py
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
@ -201,15 +201,15 @@ class TestGeneralUsage(object):
testdir.tmpdir.join("py").mksymlinkto(py._pydir) testdir.tmpdir.join("py").mksymlinkto(py._pydir)
p = testdir.tmpdir.join("main.py") p = testdir.tmpdir.join("main.py")
p.write( p.write(
_pytest._code.Source( textwrap.dedent(
""" """\
import sys, os import sys, os
sys.path.insert(0, '') sys.path.insert(0, '')
import py import py
print (py.__file__) print(py.__file__)
print (py.__path__) print(py.__path__)
os.chdir(os.path.dirname(os.getcwd())) os.chdir(os.path.dirname(os.getcwd()))
print (py.log) print(py.log)
""" """
) )
) )

View File

@ -4,6 +4,7 @@ import sys
import _pytest._code import _pytest._code
import pytest import pytest
import mock
from test_excinfo import TWMock from test_excinfo import TWMock
from six import text_type from six import text_type
@ -67,12 +68,8 @@ def test_getstatement_empty_fullsource():
f = func() f = func()
f = _pytest._code.Frame(f) f = _pytest._code.Frame(f)
prop = f.code.__class__.fullsource with mock.patch.object(f.code.__class__, "fullsource", None):
try: assert f.statement == ""
f.code.__class__.fullsource = None
assert f.statement == _pytest._code.Source("")
finally:
f.code.__class__.fullsource = prop
def test_code_from_func(): def test_code_from_func():

View File

@ -426,7 +426,7 @@ class TestFormattedExcinfo(object):
@pytest.fixture @pytest.fixture
def importasmod(self, request): def importasmod(self, request):
def importasmod(source): def importasmod(source):
source = _pytest._code.Source(source) source = textwrap.dedent(source)
tmpdir = request.getfixturevalue("tmpdir") tmpdir = request.getfixturevalue("tmpdir")
modpath = tmpdir.join("mod.py") modpath = tmpdir.join("mod.py")
tmpdir.ensure("__init__.py") tmpdir.ensure("__init__.py")
@ -450,7 +450,7 @@ class TestFormattedExcinfo(object):
def test_repr_source(self): def test_repr_source(self):
pr = FormattedExcinfo() pr = FormattedExcinfo()
source = _pytest._code.Source( source = _pytest._code.Source(
""" """\
def f(x): def f(x):
pass pass
""" """

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import sys import sys
from textwrap import dedent import textwrap
import _pytest._code import _pytest._code
import pytest import pytest
@ -47,13 +47,14 @@ class TestModule(object):
p = root2.join("test_x456.py") p = root2.join("test_x456.py")
monkeypatch.syspath_prepend(str(root1)) monkeypatch.syspath_prepend(str(root1))
p.write( p.write(
dedent( textwrap.dedent(
"""\ """\
import x456 import x456
def test(): def test():
assert x456.__file__.startswith(%r) assert x456.__file__.startswith({!r})
""" """.format(
% str(root2) str(root2)
)
) )
) )
with root2.as_cwd(): with root2.as_cwd():
@ -929,8 +930,8 @@ class TestConftestCustomization(object):
def test_customized_pymakemodule_issue205_subdir(self, testdir): def test_customized_pymakemodule_issue205_subdir(self, testdir):
b = testdir.mkdir("a").mkdir("b") b = testdir.mkdir("a").mkdir("b")
b.join("conftest.py").write( b.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_pycollect_makemodule(): def pytest_pycollect_makemodule():
@ -941,8 +942,8 @@ class TestConftestCustomization(object):
) )
) )
b.join("test_module.py").write( b.join("test_module.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_hello(): def test_hello():
assert hello == "world" assert hello == "world"
""" """
@ -954,8 +955,8 @@ class TestConftestCustomization(object):
def test_customized_pymakeitem(self, testdir): def test_customized_pymakeitem(self, testdir):
b = testdir.mkdir("a").mkdir("b") b = testdir.mkdir("a").mkdir("b")
b.join("conftest.py").write( b.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_pycollect_makeitem(): def pytest_pycollect_makeitem():
@ -969,8 +970,8 @@ class TestConftestCustomization(object):
) )
) )
b.join("test_module.py").write( b.join("test_module.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture() @pytest.fixture()
@ -1033,7 +1034,7 @@ class TestConftestCustomization(object):
) )
testdir.makefile( testdir.makefile(
".narf", ".narf",
""" """\
def test_something(): def test_something():
assert 1 + 1 == 2""", assert 1 + 1 == 2""",
) )
@ -1046,8 +1047,8 @@ def test_setup_only_available_in_subdir(testdir):
sub1 = testdir.mkpydir("sub1") sub1 = testdir.mkpydir("sub1")
sub2 = testdir.mkpydir("sub2") sub2 = testdir.mkpydir("sub2")
sub1.join("conftest.py").write( sub1.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
assert item.fspath.purebasename == "test_in_sub1" assert item.fspath.purebasename == "test_in_sub1"
@ -1059,8 +1060,8 @@ def test_setup_only_available_in_subdir(testdir):
) )
) )
sub2.join("conftest.py").write( sub2.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
assert item.fspath.purebasename == "test_in_sub2" assert item.fspath.purebasename == "test_in_sub2"
@ -1547,8 +1548,8 @@ def test_skip_duplicates_by_default(testdir):
a = testdir.mkdir("a") a = testdir.mkdir("a")
fh = a.join("test_a.py") fh = a.join("test_a.py")
fh.write( fh.write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
def test_real(): def test_real():
pass pass
@ -1567,8 +1568,8 @@ def test_keep_duplicates(testdir):
a = testdir.mkdir("a") a = testdir.mkdir("a")
fh = a.join("test_a.py") fh = a.join("test_a.py")
fh.write( fh.write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
def test_real(): def test_real():
pass pass

View File

@ -1,6 +1,5 @@
from textwrap import dedent import textwrap
import _pytest._code
import pytest import pytest
from _pytest.pytester import get_public_names from _pytest.pytester import get_public_names
from _pytest.fixtures import FixtureLookupError, FixtureRequest from _pytest.fixtures import FixtureLookupError, FixtureRequest
@ -208,8 +207,8 @@ class TestFillFixtures(object):
) )
subdir = testdir.mkpydir("subdir") subdir = testdir.mkpydir("subdir")
subdir.join("conftest.py").write( subdir.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -220,8 +219,8 @@ class TestFillFixtures(object):
) )
testfile = subdir.join("test_spam.py") testfile = subdir.join("test_spam.py")
testfile.write( testfile.write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_spam(spam): def test_spam(spam):
assert spam == "spam" assert spam == "spam"
""" """
@ -276,8 +275,8 @@ class TestFillFixtures(object):
) )
subdir = testdir.mkpydir("subdir") subdir = testdir.mkpydir("subdir")
subdir.join("conftest.py").write( subdir.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture(params=[1, 2, 3]) @pytest.fixture(params=[1, 2, 3])
@ -288,8 +287,8 @@ class TestFillFixtures(object):
) )
testfile = subdir.join("test_spam.py") testfile = subdir.join("test_spam.py")
testfile.write( testfile.write(
_pytest._code.Source( textwrap.dedent(
""" """\
params = {'spam': 1} params = {'spam': 1}
def test_spam(spam): def test_spam(spam):
@ -320,8 +319,8 @@ class TestFillFixtures(object):
) )
subdir = testdir.mkpydir("subdir") subdir = testdir.mkpydir("subdir")
subdir.join("conftest.py").write( subdir.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture(params=[1, 2, 3]) @pytest.fixture(params=[1, 2, 3])
@ -332,8 +331,8 @@ class TestFillFixtures(object):
) )
testfile = subdir.join("test_spam.py") testfile = subdir.join("test_spam.py")
testfile.write( testfile.write(
_pytest._code.Source( textwrap.dedent(
""" """\
params = {'spam': 1} params = {'spam': 1}
def test_spam(spam): def test_spam(spam):
@ -807,8 +806,8 @@ class TestRequestBasic(object):
# this tests that normalization of nodeids takes place # this tests that normalization of nodeids takes place
b = testdir.mkdir("tests").mkdir("unit") b = testdir.mkdir("tests").mkdir("unit")
b.join("conftest.py").write( b.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
def arg1(): def arg1():
@ -1484,7 +1483,7 @@ class TestFixtureManagerParseFactories(object):
runner = testdir.mkdir("runner") runner = testdir.mkdir("runner")
package = testdir.mkdir("package") package = testdir.mkdir("package")
package.join("conftest.py").write( package.join("conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -1494,7 +1493,7 @@ class TestFixtureManagerParseFactories(object):
) )
) )
package.join("test_x.py").write( package.join("test_x.py").write(
dedent( textwrap.dedent(
"""\ """\
def test_x(one): def test_x(one):
assert one == 1 assert one == 1
@ -1504,7 +1503,7 @@ class TestFixtureManagerParseFactories(object):
sub = package.mkdir("sub") sub = package.mkdir("sub")
sub.join("__init__.py").ensure() sub.join("__init__.py").ensure()
sub.join("conftest.py").write( sub.join("conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -1514,7 +1513,7 @@ class TestFixtureManagerParseFactories(object):
) )
) )
sub.join("test_y.py").write( sub.join("test_y.py").write(
dedent( textwrap.dedent(
"""\ """\
def test_x(one): def test_x(one):
assert one == 2 assert one == 2
@ -1535,7 +1534,7 @@ class TestFixtureManagerParseFactories(object):
) )
package = testdir.mkdir("package") package = testdir.mkdir("package")
package.join("__init__.py").write( package.join("__init__.py").write(
dedent( textwrap.dedent(
"""\ """\
from .. import values from .. import values
def setup_module(): def setup_module():
@ -1546,7 +1545,7 @@ class TestFixtureManagerParseFactories(object):
) )
) )
package.join("test_x.py").write( package.join("test_x.py").write(
dedent( textwrap.dedent(
"""\ """\
from .. import values from .. import values
def test_x(): def test_x():
@ -1556,7 +1555,7 @@ class TestFixtureManagerParseFactories(object):
) )
package = testdir.mkdir("package2") package = testdir.mkdir("package2")
package.join("__init__.py").write( package.join("__init__.py").write(
dedent( textwrap.dedent(
"""\ """\
from .. import values from .. import values
def setup_module(): def setup_module():
@ -1567,7 +1566,7 @@ class TestFixtureManagerParseFactories(object):
) )
) )
package.join("test_x.py").write( package.join("test_x.py").write(
dedent( textwrap.dedent(
"""\ """\
from .. import values from .. import values
def test_x(): def test_x():
@ -1587,7 +1586,7 @@ class TestFixtureManagerParseFactories(object):
package = testdir.mkdir("package") package = testdir.mkdir("package")
package.join("__init__.py").write("") package.join("__init__.py").write("")
package.join("conftest.py").write( package.join("conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
import pytest import pytest
from .. import values from .. import values
@ -1605,7 +1604,7 @@ class TestFixtureManagerParseFactories(object):
) )
) )
package.join("test_x.py").write( package.join("test_x.py").write(
dedent( textwrap.dedent(
"""\ """\
from .. import values from .. import values
def test_package_autouse(): def test_package_autouse():
@ -1804,8 +1803,8 @@ class TestAutouseManagement(object):
def test_autouse_conftest_mid_directory(self, testdir): def test_autouse_conftest_mid_directory(self, testdir):
pkgdir = testdir.mkpydir("xyz123") pkgdir = testdir.mkpydir("xyz123")
pkgdir.join("conftest.py").write( pkgdir.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def app(): def app():
@ -1816,8 +1815,8 @@ class TestAutouseManagement(object):
) )
t = pkgdir.ensure("tests", "test_app.py") t = pkgdir.ensure("tests", "test_app.py")
t.write( t.write(
_pytest._code.Source( textwrap.dedent(
""" """\
import sys import sys
def test_app(): def test_app():
assert sys._myapp == "hello" assert sys._myapp == "hello"
@ -2715,8 +2714,8 @@ class TestFixtureMarker(object):
) )
b = testdir.mkdir("subdir") b = testdir.mkdir("subdir")
b.join("test_overridden_fixture_finalizer.py").write( b.join("test_overridden_fixture_finalizer.py").write(
dedent( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
def browser(browser): def browser(browser):
@ -3217,8 +3216,8 @@ class TestShowFixtures(object):
def test_show_fixtures_trimmed_doc(self, testdir): def test_show_fixtures_trimmed_doc(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
dedent( textwrap.dedent(
''' '''\
import pytest import pytest
@pytest.fixture @pytest.fixture
def arg1(): def arg1():
@ -3239,8 +3238,8 @@ class TestShowFixtures(object):
) )
result = testdir.runpytest("--fixtures", p) result = testdir.runpytest("--fixtures", p)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
dedent( textwrap.dedent(
""" """\
* fixtures defined from test_show_fixtures_trimmed_doc * * fixtures defined from test_show_fixtures_trimmed_doc *
arg2 arg2
line1 line1
@ -3248,15 +3247,14 @@ class TestShowFixtures(object):
arg1 arg1
line1 line1
line2 line2
""" """
) )
) )
def test_show_fixtures_indented_doc(self, testdir): def test_show_fixtures_indented_doc(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
dedent( textwrap.dedent(
''' '''\
import pytest import pytest
@pytest.fixture @pytest.fixture
def fixture1(): def fixture1():
@ -3269,8 +3267,8 @@ class TestShowFixtures(object):
) )
result = testdir.runpytest("--fixtures", p) result = testdir.runpytest("--fixtures", p)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
dedent( textwrap.dedent(
""" """\
* fixtures defined from test_show_fixtures_indented_doc * * fixtures defined from test_show_fixtures_indented_doc *
fixture1 fixture1
line1 line1
@ -3281,8 +3279,8 @@ class TestShowFixtures(object):
def test_show_fixtures_indented_doc_first_line_unindented(self, testdir): def test_show_fixtures_indented_doc_first_line_unindented(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
dedent( textwrap.dedent(
''' '''\
import pytest import pytest
@pytest.fixture @pytest.fixture
def fixture1(): def fixture1():
@ -3295,8 +3293,8 @@ class TestShowFixtures(object):
) )
result = testdir.runpytest("--fixtures", p) result = testdir.runpytest("--fixtures", p)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
dedent( textwrap.dedent(
""" """\
* fixtures defined from test_show_fixtures_indented_doc_first_line_unindented * * fixtures defined from test_show_fixtures_indented_doc_first_line_unindented *
fixture1 fixture1
line1 line1
@ -3308,8 +3306,8 @@ class TestShowFixtures(object):
def test_show_fixtures_indented_in_class(self, testdir): def test_show_fixtures_indented_in_class(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
dedent( textwrap.dedent(
''' '''\
import pytest import pytest
class TestClass(object): class TestClass(object):
@pytest.fixture @pytest.fixture
@ -3323,8 +3321,8 @@ class TestShowFixtures(object):
) )
result = testdir.runpytest("--fixtures", p) result = testdir.runpytest("--fixtures", p)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
dedent( textwrap.dedent(
""" """\
* fixtures defined from test_show_fixtures_indented_in_class * * fixtures defined from test_show_fixtures_indented_in_class *
fixture1 fixture1
line1 line1
@ -3667,8 +3665,8 @@ class TestParameterizedSubRequest(object):
fixdir = testdir.mkdir("fixtures") fixdir = testdir.mkdir("fixtures")
fixfile = fixdir.join("fix.py") fixfile = fixdir.join("fix.py")
fixfile.write( fixfile.write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture(params=[0, 1, 2]) @pytest.fixture(params=[0, 1, 2])
@ -3680,8 +3678,8 @@ class TestParameterizedSubRequest(object):
testfile = tests_dir.join("test_foos.py") testfile = tests_dir.join("test_foos.py")
testfile.write( testfile.write(
_pytest._code.Source( textwrap.dedent(
""" """\
from fix import fix_with_param from fix import fix_with_param
def test_foo(request): def test_foo(request):
@ -3698,9 +3696,9 @@ class TestParameterizedSubRequest(object):
E*Failed: The requested fixture has no parameter defined for the current test. E*Failed: The requested fixture has no parameter defined for the current test.
E* E*
E*Requested fixture 'fix_with_param' defined in: E*Requested fixture 'fix_with_param' defined in:
E*fix.py:5 E*fix.py:4
E*Requested here: E*Requested here:
E*test_foos.py:5 E*test_foos.py:4
*1 failed* *1 failed*
""" """
) )

View File

@ -2,7 +2,7 @@
import re import re
import sys import sys
import attr import attr
import _pytest._code import textwrap
import pytest import pytest
from _pytest import python, fixtures from _pytest import python, fixtures
@ -1271,16 +1271,16 @@ class TestMetafuncFunctional(object):
sub1 = testdir.mkpydir("sub1") sub1 = testdir.mkpydir("sub1")
sub2 = testdir.mkpydir("sub2") sub2 = testdir.mkpydir("sub2")
sub1.join("conftest.py").write( sub1.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
assert metafunc.function.__name__ == "test_1" assert metafunc.function.__name__ == "test_1"
""" """
) )
) )
sub2.join("conftest.py").write( sub2.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
assert metafunc.function.__name__ == "test_2" assert metafunc.function.__name__ == "test_2"
""" """

View File

@ -1039,8 +1039,8 @@ class TestAssertionRewriteHookDetails(object):
""" """
path = testdir.mkpydir("foo") path = testdir.mkpydir("foo")
path.join("test_foo.py").write( path.join("test_foo.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
class Test(object): class Test(object):
def test_foo(self): def test_foo(self):
import pkgutil import pkgutil

View File

@ -1,9 +1,9 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import sys import sys
import textwrap
import py import py
import _pytest
import pytest import pytest
import os import os
import shutil import shutil
@ -224,8 +224,8 @@ class TestLastFailed(object):
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["*2 failed*"]) result.stdout.fnmatch_lines(["*2 failed*"])
p.write( p.write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_1(): def test_1():
assert 1 assert 1
@ -252,16 +252,16 @@ class TestLastFailed(object):
def test_failedfirst_order(self, testdir): def test_failedfirst_order(self, testdir):
testdir.tmpdir.join("test_a.py").write( testdir.tmpdir.join("test_a.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_always_passes(): def test_always_passes():
assert 1 assert 1
""" """
) )
) )
testdir.tmpdir.join("test_b.py").write( testdir.tmpdir.join("test_b.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_always_fails(): def test_always_fails():
assert 0 assert 0
""" """
@ -277,11 +277,11 @@ class TestLastFailed(object):
def test_lastfailed_failedfirst_order(self, testdir): def test_lastfailed_failedfirst_order(self, testdir):
testdir.makepyfile( testdir.makepyfile(
**{ **{
"test_a.py": """ "test_a.py": """\
def test_always_passes(): def test_always_passes():
assert 1 assert 1
""", """,
"test_b.py": """ "test_b.py": """\
def test_always_fails(): def test_always_fails():
assert 0 assert 0
""", """,
@ -298,13 +298,13 @@ class TestLastFailed(object):
def test_lastfailed_difference_invocations(self, testdir, monkeypatch): def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1) monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
testdir.makepyfile( testdir.makepyfile(
test_a=""" test_a="""\
def test_a1(): def test_a1():
assert 0 assert 0
def test_a2(): def test_a2():
assert 1 assert 1
""", """,
test_b=""" test_b="""\
def test_b1(): def test_b1():
assert 0 assert 0
""", """,
@ -317,8 +317,8 @@ class TestLastFailed(object):
result = testdir.runpytest("--lf", p2) result = testdir.runpytest("--lf", p2)
result.stdout.fnmatch_lines(["*1 failed*"]) result.stdout.fnmatch_lines(["*1 failed*"])
p2.write( p2.write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_b1(): def test_b1():
assert 1 assert 1
""" """
@ -332,15 +332,15 @@ class TestLastFailed(object):
def test_lastfailed_usecase_splice(self, testdir, monkeypatch): def test_lastfailed_usecase_splice(self, testdir, monkeypatch):
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1) monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_1(): def test_1():
assert 0 assert 0
""" """
) )
p2 = testdir.tmpdir.join("test_something.py") p2 = testdir.tmpdir.join("test_something.py")
p2.write( p2.write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_2(): def test_2():
assert 0 assert 0
""" """

View File

@ -6,9 +6,9 @@ from __future__ import absolute_import, division, print_function
import pickle import pickle
import os import os
import sys import sys
import textwrap
from io import UnsupportedOperation from io import UnsupportedOperation
import _pytest._code
import py import py
import pytest import pytest
import contextlib import contextlib
@ -269,7 +269,7 @@ class TestPerTestCapturing(object):
def test_capturing_outerr(self, testdir): def test_capturing_outerr(self, testdir):
p1 = testdir.makepyfile( p1 = testdir.makepyfile(
""" """\
import sys import sys
def test_capturing(): def test_capturing():
print (42) print (42)
@ -298,7 +298,7 @@ class TestPerTestCapturing(object):
class TestLoggingInteraction(object): class TestLoggingInteraction(object):
def test_logging_stream_ownership(self, testdir): def test_logging_stream_ownership(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_logging(): def test_logging():
import logging import logging
import pytest import pytest
@ -312,7 +312,7 @@ class TestLoggingInteraction(object):
def test_logging_and_immediate_setupteardown(self, testdir): def test_logging_and_immediate_setupteardown(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
import logging import logging
def setup_function(function): def setup_function(function):
logging.warn("hello1") logging.warn("hello1")
@ -338,7 +338,7 @@ class TestLoggingInteraction(object):
def test_logging_and_crossscope_fixtures(self, testdir): def test_logging_and_crossscope_fixtures(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
import logging import logging
def setup_module(function): def setup_module(function):
logging.warn("hello1") logging.warn("hello1")
@ -364,7 +364,7 @@ class TestLoggingInteraction(object):
def test_conftestlogging_is_shown(self, testdir): def test_conftestlogging_is_shown(self, testdir):
testdir.makeconftest( testdir.makeconftest(
""" """\
import logging import logging
logging.basicConfig() logging.basicConfig()
logging.warn("hello435") logging.warn("hello435")
@ -378,14 +378,14 @@ class TestLoggingInteraction(object):
def test_conftestlogging_and_test_logging(self, testdir): def test_conftestlogging_and_test_logging(self, testdir):
testdir.makeconftest( testdir.makeconftest(
""" """\
import logging import logging
logging.basicConfig() logging.basicConfig()
""" """
) )
# make sure that logging is still captured in tests # make sure that logging is still captured in tests
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_hello(): def test_hello():
import logging import logging
logging.warn("hello433") logging.warn("hello433")
@ -403,7 +403,7 @@ class TestCaptureFixture(object):
@pytest.mark.parametrize("opt", [[], ["-s"]]) @pytest.mark.parametrize("opt", [[], ["-s"]])
def test_std_functional(self, testdir, opt): def test_std_functional(self, testdir, opt):
reprec = testdir.inline_runsource( reprec = testdir.inline_runsource(
""" """\
def test_hello(capsys): def test_hello(capsys):
print (42) print (42)
out, err = capsys.readouterr() out, err = capsys.readouterr()
@ -415,7 +415,7 @@ class TestCaptureFixture(object):
def test_capsyscapfd(self, testdir): def test_capsyscapfd(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_one(capsys, capfd): def test_one(capsys, capfd):
pass pass
def test_two(capfd, capsys): def test_two(capfd, capsys):
@ -438,7 +438,7 @@ class TestCaptureFixture(object):
in the same test is an error. in the same test is an error.
""" """
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_one(capsys, request): def test_one(capsys, request):
request.getfixturevalue("capfd") request.getfixturevalue("capfd")
def test_two(capfd, request): def test_two(capfd, request):
@ -458,7 +458,7 @@ class TestCaptureFixture(object):
def test_capsyscapfdbinary(self, testdir): def test_capsyscapfdbinary(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_one(capsys, capfdbinary): def test_one(capsys, capfdbinary):
pass pass
""" """
@ -471,12 +471,13 @@ class TestCaptureFixture(object):
@pytest.mark.parametrize("method", ["sys", "fd"]) @pytest.mark.parametrize("method", ["sys", "fd"])
def test_capture_is_represented_on_failure_issue128(self, testdir, method): def test_capture_is_represented_on_failure_issue128(self, testdir, method):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_hello(cap%s): def test_hello(cap{}):
print ("xxx42xxx") print ("xxx42xxx")
assert 0 assert 0
""" """.format(
% method method
)
) )
result = testdir.runpytest(p) result = testdir.runpytest(p)
result.stdout.fnmatch_lines(["xxx42xxx"]) result.stdout.fnmatch_lines(["xxx42xxx"])
@ -484,7 +485,7 @@ class TestCaptureFixture(object):
@needsosdup @needsosdup
def test_stdfd_functional(self, testdir): def test_stdfd_functional(self, testdir):
reprec = testdir.inline_runsource( reprec = testdir.inline_runsource(
""" """\
def test_hello(capfd): def test_hello(capfd):
import os import os
os.write(1, "42".encode('ascii')) os.write(1, "42".encode('ascii'))
@ -498,7 +499,7 @@ class TestCaptureFixture(object):
@needsosdup @needsosdup
def test_capfdbinary(self, testdir): def test_capfdbinary(self, testdir):
reprec = testdir.inline_runsource( reprec = testdir.inline_runsource(
""" """\
def test_hello(capfdbinary): def test_hello(capfdbinary):
import os import os
# some likely un-decodable bytes # some likely un-decodable bytes
@ -515,7 +516,7 @@ class TestCaptureFixture(object):
) )
def test_capsysbinary(self, testdir): def test_capsysbinary(self, testdir):
reprec = testdir.inline_runsource( reprec = testdir.inline_runsource(
""" """\
def test_hello(capsysbinary): def test_hello(capsysbinary):
import sys import sys
# some likely un-decodable bytes # some likely un-decodable bytes
@ -532,7 +533,7 @@ class TestCaptureFixture(object):
) )
def test_capsysbinary_forbidden_in_python2(self, testdir): def test_capsysbinary_forbidden_in_python2(self, testdir):
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_hello(capsysbinary): def test_hello(capsysbinary):
pass pass
""" """
@ -548,7 +549,7 @@ class TestCaptureFixture(object):
def test_partial_setup_failure(self, testdir): def test_partial_setup_failure(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_hello(capsys, missingarg): def test_hello(capsys, missingarg):
pass pass
""" """
@ -559,7 +560,7 @@ class TestCaptureFixture(object):
@needsosdup @needsosdup
def test_keyboardinterrupt_disables_capturing(self, testdir): def test_keyboardinterrupt_disables_capturing(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
def test_hello(capfd): def test_hello(capfd):
import os import os
os.write(1, str(42).encode('ascii')) os.write(1, str(42).encode('ascii'))
@ -573,7 +574,7 @@ class TestCaptureFixture(object):
@pytest.mark.issue14 @pytest.mark.issue14
def test_capture_and_logging(self, testdir): def test_capture_and_logging(self, testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
import logging import logging
def test_log(capsys): def test_log(capsys):
logging.error('x') logging.error('x')
@ -586,7 +587,7 @@ class TestCaptureFixture(object):
@pytest.mark.parametrize("no_capture", [True, False]) @pytest.mark.parametrize("no_capture", [True, False])
def test_disabled_capture_fixture(self, testdir, fixture, no_capture): def test_disabled_capture_fixture(self, testdir, fixture, no_capture):
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_disabled({fixture}): def test_disabled({fixture}):
print('captured before') print('captured before')
with {fixture}.disabled(): with {fixture}.disabled():
@ -620,7 +621,7 @@ class TestCaptureFixture(object):
Ensure that capsys and capfd can be used by other fixtures during setup and teardown. Ensure that capsys and capfd can be used by other fixtures during setup and teardown.
""" """
testdir.makepyfile( testdir.makepyfile(
""" """\
from __future__ import print_function from __future__ import print_function
import sys import sys
import pytest import pytest
@ -656,7 +657,7 @@ class TestCaptureFixture(object):
def test_fixture_use_by_other_fixtures_teardown(self, testdir, cap): def test_fixture_use_by_other_fixtures_teardown(self, testdir, cap):
"""Ensure we can access setup and teardown buffers from teardown when using capsys/capfd (##3033)""" """Ensure we can access setup and teardown buffers from teardown when using capsys/capfd (##3033)"""
testdir.makepyfile( testdir.makepyfile(
""" """\
import sys import sys
import pytest import pytest
import os import os
@ -684,8 +685,8 @@ class TestCaptureFixture(object):
def test_setup_failure_does_not_kill_capturing(testdir): def test_setup_failure_does_not_kill_capturing(testdir):
sub1 = testdir.mkpydir("sub1") sub1 = testdir.mkpydir("sub1")
sub1.join("conftest.py").write( sub1.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
raise ValueError(42) raise ValueError(42)
""" """

View File

@ -1,9 +1,9 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import pprint import pprint
import sys import sys
import textwrap
import pytest import pytest
import _pytest._code
from _pytest.main import Session, EXIT_NOTESTSCOLLECTED, _in_venv from _pytest.main import Session, EXIT_NOTESTSCOLLECTED, _in_venv
@ -913,8 +913,8 @@ def test_fixture_scope_sibling_conftests(testdir):
"""Regression test case for https://github.com/pytest-dev/pytest/issues/2836""" """Regression test case for https://github.com/pytest-dev/pytest/issues/2836"""
foo_path = testdir.mkdir("foo") foo_path = testdir.mkdir("foo")
foo_path.join("conftest.py").write( foo_path.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
def fix(): def fix():

View File

@ -17,8 +17,8 @@ class TestParseIni(object):
sub = tmpdir.mkdir("sub") sub = tmpdir.mkdir("sub")
sub.chdir() sub.chdir()
tmpdir.join(filename).write( tmpdir.join(filename).write(
_pytest._code.Source( textwrap.dedent(
""" """\
[{section}] [{section}]
name = value name = value
""".format( """.format(
@ -38,8 +38,8 @@ class TestParseIni(object):
def test_append_parse_args(self, testdir, tmpdir, monkeypatch): def test_append_parse_args(self, testdir, tmpdir, monkeypatch):
monkeypatch.setenv("PYTEST_ADDOPTS", '--color no -rs --tb="short"') monkeypatch.setenv("PYTEST_ADDOPTS", '--color no -rs --tb="short"')
tmpdir.join("pytest.ini").write( tmpdir.join("pytest.ini").write(
_pytest._code.Source( textwrap.dedent(
""" """\
[pytest] [pytest]
addopts = --verbose addopts = --verbose
""" """
@ -438,8 +438,8 @@ class TestConfigFromdictargs(object):
def test_inifilename(self, tmpdir): def test_inifilename(self, tmpdir):
tmpdir.join("foo/bar.ini").ensure().write( tmpdir.join("foo/bar.ini").ensure().write(
_pytest._code.Source( textwrap.dedent(
""" """\
[pytest] [pytest]
name = value name = value
""" """
@ -453,8 +453,8 @@ class TestConfigFromdictargs(object):
cwd = tmpdir.join("a/b") cwd = tmpdir.join("a/b")
cwd.join("pytest.ini").ensure().write( cwd.join("pytest.ini").ensure().write(
_pytest._code.Source( textwrap.dedent(
""" """\
[pytest] [pytest]
name = wrong-value name = wrong-value
should_not_be_set = true should_not_be_set = true

View File

@ -1,7 +1,6 @@
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
from textwrap import dedent import textwrap
import _pytest._code
import py import py
import pytest import pytest
from _pytest.config import PytestPluginManager from _pytest.config import PytestPluginManager
@ -174,8 +173,8 @@ def test_conftest_confcutdir(testdir):
testdir.makeconftest("assert 0") testdir.makeconftest("assert 0")
x = testdir.mkdir("x") x = testdir.mkdir("x")
x.join("conftest.py").write( x.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--xyz", action="store_true") parser.addoption("--xyz", action="store_true")
""" """
@ -198,8 +197,8 @@ def test_no_conftest(testdir):
def test_conftest_existing_resultlog(testdir): def test_conftest_existing_resultlog(testdir):
x = testdir.mkdir("tests") x = testdir.mkdir("tests")
x.join("conftest.py").write( x.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--xyz", action="store_true") parser.addoption("--xyz", action="store_true")
""" """
@ -213,8 +212,8 @@ def test_conftest_existing_resultlog(testdir):
def test_conftest_existing_junitxml(testdir): def test_conftest_existing_junitxml(testdir):
x = testdir.mkdir("tests") x = testdir.mkdir("tests")
x.join("conftest.py").write( x.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--xyz", action="store_true") parser.addoption("--xyz", action="store_true")
""" """
@ -247,8 +246,8 @@ def test_fixture_dependency(testdir, monkeypatch):
sub = testdir.mkdir("sub") sub = testdir.mkdir("sub")
sub.join("__init__.py").write("") sub.join("__init__.py").write("")
sub.join("conftest.py").write( sub.join("conftest.py").write(
dedent( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -268,8 +267,8 @@ def test_fixture_dependency(testdir, monkeypatch):
subsub = sub.mkdir("subsub") subsub = sub.mkdir("subsub")
subsub.join("__init__.py").write("") subsub.join("__init__.py").write("")
subsub.join("test_bar.py").write( subsub.join("test_bar.py").write(
dedent( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -288,8 +287,8 @@ def test_fixture_dependency(testdir, monkeypatch):
def test_conftest_found_with_double_dash(testdir): def test_conftest_found_with_double_dash(testdir):
sub = testdir.mkdir("sub") sub = testdir.mkdir("sub")
sub.join("conftest.py").write( sub.join("conftest.py").write(
dedent( textwrap.dedent(
""" """\
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--hello-world", action="store_true") parser.addoption("--hello-world", action="store_true")
""" """
@ -313,7 +312,7 @@ class TestConftestVisibility(object):
package = testdir.mkdir("package") package = testdir.mkdir("package")
package.join("conftest.py").write( package.join("conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -323,7 +322,7 @@ class TestConftestVisibility(object):
) )
) )
package.join("test_pkgroot.py").write( package.join("test_pkgroot.py").write(
dedent( textwrap.dedent(
"""\ """\
def test_pkgroot(fxtr): def test_pkgroot(fxtr):
assert fxtr == "from-package" assert fxtr == "from-package"
@ -334,7 +333,7 @@ class TestConftestVisibility(object):
swc = package.mkdir("swc") swc = package.mkdir("swc")
swc.join("__init__.py").ensure() swc.join("__init__.py").ensure()
swc.join("conftest.py").write( swc.join("conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
import pytest import pytest
@pytest.fixture @pytest.fixture
@ -344,11 +343,10 @@ class TestConftestVisibility(object):
) )
) )
swc.join("test_with_conftest.py").write( swc.join("test_with_conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
def test_with_conftest(fxtr): def test_with_conftest(fxtr):
assert fxtr == "from-swc" assert fxtr == "from-swc"
""" """
) )
) )
@ -356,12 +354,11 @@ class TestConftestVisibility(object):
snc = package.mkdir("snc") snc = package.mkdir("snc")
snc.join("__init__.py").ensure() snc.join("__init__.py").ensure()
snc.join("test_no_conftest.py").write( snc.join("test_no_conftest.py").write(
dedent( textwrap.dedent(
"""\ """\
def test_no_conftest(fxtr): def test_no_conftest(fxtr):
assert fxtr == "from-package" # No local conftest.py, so should assert fxtr == "from-package" # No local conftest.py, so should
# use value from parent dir's # use value from parent dir's
""" """
) )
) )
@ -422,8 +419,8 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error):
src = root.join("src").ensure(dir=1) src = root.join("src").ensure(dir=1)
src.join("pytest.ini").write("[pytest]") src.join("pytest.ini").write("[pytest]")
src.join("conftest.py").write( src.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
def fix1(): pass def fix1(): pass
@ -431,8 +428,8 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error):
) )
) )
src.join("test_foo.py").write( src.join("test_foo.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def test_1(fix1): def test_1(fix1):
pass pass
def test_2(out_of_reach): def test_2(out_of_reach):
@ -441,8 +438,8 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error):
) )
) )
root.join("conftest.py").write( root.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import pytest import pytest
@pytest.fixture @pytest.fixture
def out_of_reach(): pass def out_of_reach(): pass
@ -464,7 +461,7 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error):
def test_issue1073_conftest_special_objects(testdir): def test_issue1073_conftest_special_objects(testdir):
testdir.makeconftest( testdir.makeconftest(
""" """\
class DontTouchMe(object): class DontTouchMe(object):
def __getattr__(self, x): def __getattr__(self, x):
raise Exception('cant touch me') raise Exception('cant touch me')
@ -473,7 +470,7 @@ def test_issue1073_conftest_special_objects(testdir):
""" """
) )
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_some(): def test_some():
pass pass
""" """
@ -484,12 +481,12 @@ def test_issue1073_conftest_special_objects(testdir):
def test_conftest_exception_handling(testdir): def test_conftest_exception_handling(testdir):
testdir.makeconftest( testdir.makeconftest(
""" """\
raise ValueError() raise ValueError()
""" """
) )
testdir.makepyfile( testdir.makepyfile(
""" """\
def test_some(): def test_some():
pass pass
""" """
@ -507,7 +504,7 @@ def test_hook_proxy(testdir):
**{ **{
"root/demo-0/test_foo1.py": "def test1(): pass", "root/demo-0/test_foo1.py": "def test1(): pass",
"root/demo-a/test_foo2.py": "def test1(): pass", "root/demo-a/test_foo2.py": "def test1(): pass",
"root/demo-a/conftest.py": """ "root/demo-a/conftest.py": """\
def pytest_ignore_collect(path, config): def pytest_ignore_collect(path, config):
return True return True
""", """,
@ -525,8 +522,8 @@ def test_required_option_help(testdir):
testdir.makeconftest("assert 0") testdir.makeconftest("assert 0")
x = testdir.mkdir("x") x = testdir.mkdir("x")
x.join("conftest.py").write( x.join("conftest.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--xyz", action="store_true", required=True) parser.addoption("--xyz", action="store_true", required=True)
""" """

View File

@ -1,7 +1,7 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import sys import sys
import _pytest._code import textwrap
from _pytest.compat import MODULE_NOT_FOUND_ERROR from _pytest.compat import MODULE_NOT_FOUND_ERROR
from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile
import pytest import pytest
@ -258,8 +258,8 @@ class TestDoctests(object):
def test_doctest_linedata_missing(self, testdir): def test_doctest_linedata_missing(self, testdir):
testdir.tmpdir.join("hello.py").write( testdir.tmpdir.join("hello.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
class Fun(object): class Fun(object):
@property @property
def test(self): def test(self):
@ -300,8 +300,8 @@ class TestDoctests(object):
def test_doctest_unex_importerror_with_module(self, testdir): def test_doctest_unex_importerror_with_module(self, testdir):
testdir.tmpdir.join("hello.py").write( testdir.tmpdir.join("hello.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
import asdalsdkjaslkdjasd import asdalsdkjaslkdjasd
""" """
) )
@ -339,8 +339,8 @@ class TestDoctests(object):
def test_doctestmodule_external_and_issue116(self, testdir): def test_doctestmodule_external_and_issue116(self, testdir):
p = testdir.mkpydir("hello") p = testdir.mkpydir("hello")
p.join("__init__.py").write( p.join("__init__.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
def somefunc(): def somefunc():
''' '''
>>> i = 0 >>> i = 0
@ -353,13 +353,13 @@ class TestDoctests(object):
result = testdir.runpytest(p, "--doctest-modules") result = testdir.runpytest(p, "--doctest-modules")
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"004 *>>> i = 0", "003 *>>> i = 0",
"005 *>>> i + 1", "004 *>>> i + 1",
"*Expected:", "*Expected:",
"* 2", "* 2",
"*Got:", "*Got:",
"* 1", "* 1",
"*:5: DocTestFailure", "*:4: DocTestFailure",
] ]
) )

View File

@ -4,9 +4,9 @@ terminal reporting of the full testing process.
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import collections import collections
import sys import sys
import textwrap
import pluggy import pluggy
import _pytest._code
import py import py
import pytest import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
@ -161,8 +161,8 @@ class TestTerminal(object):
def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir): def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir):
a = testdir.mkpydir("a123") a = testdir.mkpydir("a123")
a.join("test_hello123.py").write( a.join("test_hello123.py").write(
_pytest._code.Source( textwrap.dedent(
""" """\
class TestClass(object): class TestClass(object):
def test_method(self): def test_method(self):
pass pass
@ -312,8 +312,8 @@ class TestCollectonly(object):
result = testdir.runpytest("--collect-only", p) result = testdir.runpytest("--collect-only", p)
assert result.ret == 2 assert result.ret == 2
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
_pytest._code.Source( textwrap.dedent(
""" """\
*ERROR* *ERROR*
*ImportError* *ImportError*
*No module named *Errlk* *No module named *Errlk*