From e5021dc9dc59c73e03e3beadd14de771a4c6b1bd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 16 Mar 2017 22:27:28 -0300 Subject: [PATCH] Replace py.builtin.print_() calls by builtin print() function --- _pytest/pytester.py | 16 +++++++--------- _pytest/resultlog.py | 4 ++-- testing/python/collect.py | 10 ++++++---- testing/test_capture.py | 6 +++--- testing/test_mark.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 48d9b0956..ee0e5bbe7 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -14,8 +14,6 @@ from fnmatch import fnmatch from weakref import WeakKeyDictionary -from py.builtin import print_ - from _pytest.capture import MultiCapture, SysCapture from _pytest._code import Source import py @@ -231,15 +229,15 @@ class HookRecorder(object): name, check = entries.pop(0) for ind, call in enumerate(self.calls[i:]): if call._name == name: - print_("NAMEMATCH", name, call) + print("NAMEMATCH", name, call) if eval(check, backlocals, call.__dict__): - print_("CHECKERMATCH", repr(check), "->", call) + print("CHECKERMATCH", repr(check), "->", call) else: - print_("NOCHECKERMATCH", repr(check), "-", call) + print("NOCHECKERMATCH", repr(check), "-", call) continue i += ind + 1 break - print_("NONAMEMATCH", name, "with", call) + print("NONAMEMATCH", name, "with", call) else: pytest.fail("could not find %r check %r" % (name, check)) @@ -926,8 +924,8 @@ class Testdir(object): cmdargs = [str(x) for x in cmdargs] p1 = self.tmpdir.join("stdout") p2 = self.tmpdir.join("stderr") - print_("running:", ' '.join(cmdargs)) - print_(" in:", str(py.path.local())) + print("running:", ' '.join(cmdargs)) + print(" in:", str(py.path.local())) f1 = codecs.open(str(p1), "w", encoding="utf8") f2 = codecs.open(str(p2), "w", encoding="utf8") try: @@ -953,7 +951,7 @@ class Testdir(object): def _dump_lines(self, lines, fp): try: for line in lines: - py.builtin.print_(line, file=fp) + print(line, file=fp) except UnicodeEncodeError: print("couldn't print to %s because of encoding" % (fp,)) diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index fbf06d630..3e4b00cf9 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -62,9 +62,9 @@ class ResultLog(object): self.logfile = logfile # preferably line buffered def write_log_entry(self, testpath, lettercode, longrepr): - py.builtin.print_("%s %s" % (lettercode, testpath), file=self.logfile) + print("%s %s" % (lettercode, testpath), file=self.logfile) for line in longrepr.splitlines(): - py.builtin.print_(" %s" % line, file=self.logfile) + print(" %s" % line, file=self.logfile) def log_outcome(self, report, lettercode, longrepr): testpath = getattr(report, 'nodeid', None) diff --git a/testing/python/collect.py b/testing/python/collect.py index e4069983a..e67b6bc84 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -274,6 +274,7 @@ class TestGenerator(object): def test_order_of_execution_generator_same_codeline(self, testdir, tmpdir): o = testdir.makepyfile(""" + from __future__ import print_function def test_generative_order_of_execution(): import py, pytest test_list = [] @@ -283,8 +284,8 @@ class TestGenerator(object): test_list.append(item) def assert_order_of_execution(): - py.builtin.print_('expected order', expected_list) - py.builtin.print_('but got ', test_list) + print('expected order', expected_list) + print('but got ', test_list) assert test_list == expected_list for i in expected_list: @@ -298,6 +299,7 @@ class TestGenerator(object): def test_order_of_execution_generator_different_codeline(self, testdir): o = testdir.makepyfile(""" + from __future__ import print_function def test_generative_tests_different_codeline(): import py, pytest test_list = [] @@ -313,8 +315,8 @@ class TestGenerator(object): test_list.append(0) def assert_order_of_execution(): - py.builtin.print_('expected order', expected_list) - py.builtin.print_('but got ', test_list) + print('expected order', expected_list) + print('but got ', test_list) assert test_list == expected_list yield list_append_0 diff --git a/testing/test_capture.py b/testing/test_capture.py index 6296abe78..aa2a3bae5 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -14,7 +14,7 @@ import contextlib from _pytest import capture from _pytest.capture import CaptureManager from _pytest.main import EXIT_NOTESTSCOLLECTED -from py.builtin import print_ + needsosdup = pytest.mark.xfail("not hasattr(os, 'dup')") @@ -712,7 +712,7 @@ def test_dupfile(tmpfile): assert nf != tmpfile assert nf.fileno() != tmpfile.fileno() assert nf not in flist - print_(i, end="", file=nf) + print(i, end="", file=nf) flist.append(nf) for i in range(5): f = flist[i] @@ -786,7 +786,7 @@ class TestFDCapture(object): def test_stderr(self): cap = capture.FDCapture(2) cap.start() - print_("hello", file=sys.stderr) + print("hello", file=sys.stderr) s = cap.snap() cap.done() assert s == "hello\n" diff --git a/testing/test_mark.py b/testing/test_mark.py index 79e485438..3bec1d0d0 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -674,7 +674,7 @@ class TestKeywordSelection(object): item.extra_keyword_matches.add("xxx") """) reprec = testdir.inline_run(p.dirpath(), '-s', '-k', keyword) - py.builtin.print_("keyword", repr(keyword)) + print("keyword", repr(keyword)) passed, skipped, failed = reprec.listoutcomes() assert len(passed) == 1 assert passed[0].nodeid.endswith("test_2")