From c14a23d4e46810e613401ec095803debcf3b4af5 Mon Sep 17 00:00:00 2001 From: Niklas JQ Date: Wed, 10 Oct 2018 19:28:31 +0200 Subject: [PATCH 1/7] Fix #4093: multiple string literals on a line --- doc/en/example/assertion/failure_demo.py | 2 +- doc/en/example/reportingdemo.rst | 2 +- src/_pytest/assertion/util.py | 2 +- src/_pytest/cacheprovider.py | 2 +- src/_pytest/capture.py | 2 +- src/_pytest/compat.py | 2 +- src/_pytest/deprecated.py | 2 +- src/_pytest/helpconfig.py | 2 +- src/_pytest/python.py | 2 +- src/_pytest/recwarn.py | 2 +- src/_pytest/terminal.py | 2 +- testing/acceptance_test.py | 6 +++--- testing/logging/test_formatter.py | 4 ++-- testing/test_junitxml.py | 2 +- testing/test_pdb.py | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/en/example/assertion/failure_demo.py b/doc/en/example/assertion/failure_demo.py index 33fff5565..5dff265a5 100644 --- a/doc/en/example/assertion/failure_demo.py +++ b/doc/en/example/assertion/failure_demo.py @@ -246,7 +246,7 @@ class TestCustomAssertMsg(object): b = 2 assert A.a == b, ( - "A.a appears not to be b\n" "or does not appear to be b\none of those" + "A.a appears not to be b\nor does not appear to be b\none of those" ) def test_custom_repr(self): diff --git a/doc/en/example/reportingdemo.rst b/doc/en/example/reportingdemo.rst index a411aa49a..fb117d06c 100644 --- a/doc/en/example/reportingdemo.rst +++ b/doc/en/example/reportingdemo.rst @@ -582,7 +582,7 @@ get on the terminal - we are working on that):: b = 2 > assert ( A.a == b - ), "A.a appears not to be b\n" "or does not appear to be b\none of those" + ), "A.a appears not to be b\nor does not appear to be b\none of those" E AssertionError: A.a appears not to be b E or does not appear to be b E one of those diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index a3013cb98..15724ed32 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -199,7 +199,7 @@ def _diff_text(left, right, verbose=False): if i > 42: i -= 10 # Provide some context explanation = [ - u("Skipping %s identical leading " "characters in diff, use -v to show") + u("Skipping %s identical leading characters in diff, use -v to show") % i ] left = left[i:] diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 87e24894b..dc71303c0 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -344,7 +344,7 @@ def cacheshow(config, session): key = valpath.relative_to(vdir) val = config.cache.get(key, dummy) if val is dummy: - tw.line("%s contains unreadable content, " "will be ignored" % key) + tw.line("%s contains unreadable content, will be ignored" % key) else: tw.line("%s contains:" % key) for line in pformat(val).splitlines(): diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 97b88ee9d..dfb488968 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -654,7 +654,7 @@ class DontReadFromInput(six.Iterator): return self def fileno(self): - raise UnsupportedOperation("redirected stdin is pseudofile, " "has no fileno()") + raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()") def isatty(self): return False diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 02cad24cc..6f48cdc3f 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -275,7 +275,7 @@ def get_real_func(obj): obj = new_obj else: raise ValueError( - ("could not find real function of {start}" "\nstopped at {current}").format( + ("could not find real function of {start}\nstopped at {current}").format( start=py.io.saferepr(start_obj), current=py.io.saferepr(obj) ) ) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index dea8bbde8..c26cf4879 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -64,7 +64,7 @@ RECORD_XML_PROPERTY = RemovedInPytest4Warning( ) COLLECTOR_MAKEITEM = RemovedInPytest4Warning( - "pycollector makeitem was removed " "as it is an accidentially leaked internal api" + "pycollector makeitem was removed as it is an accidentially leaked internal api" ) METAFUNC_ADD_CALL = RemovedInPytest4Warning( diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py index 85f071e9e..88bef95fc 100644 --- a/src/_pytest/helpconfig.py +++ b/src/_pytest/helpconfig.py @@ -139,7 +139,7 @@ def showhelp(config): tw.line() tw.line() tw.line( - "[pytest] ini-options in the first " "pytest.ini|tox.ini|setup.cfg file found:" + "[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:" ) tw.line() diff --git a/src/_pytest/python.py b/src/_pytest/python.py index e83ea7a26..0717301ed 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -131,7 +131,7 @@ def pytest_addoption(parser): "python_functions", type="args", default=["test"], - help="prefixes or glob names for Python test function and " "method discovery", + help="prefixes or glob names for Python test function and method discovery", ) group.addoption( diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 7a0586697..e1b674fa8 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -196,7 +196,7 @@ class WarningsChecker(WarningsRecorder): def __init__(self, expected_warning=None, match_expr=None): super(WarningsChecker, self).__init__() - msg = "exceptions must be old-style classes or " "derived from Warning, not %s" + msg = "exceptions must be old-style classes or derived from Warning, not %s" if isinstance(expected_warning, tuple): for exc in expected_warning: if not inspect.isclass(exc): diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 125eb97c4..a7a45da57 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -836,7 +836,7 @@ def repr_pythonversion(v=None): def build_summary_stats_line(stats): keys = ( - "failed passed skipped deselected " "xfailed xpassed warnings error" + "failed passed skipped deselected xfailed xpassed warnings error" ).split() unknown_key_seen = False for key in stats.keys(): diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 332af27b5..b0d0a7e61 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -608,7 +608,7 @@ class TestInvocationVariants(object): lib = ns.mkdir(dirname) lib.ensure("__init__.py") lib.join("test_{}.py".format(dirname)).write( - "def test_{}(): pass\n" "def test_other():pass".format(dirname) + "def test_{}(): pass\ndef test_other():pass".format(dirname) ) # The structure of the test directory is now: @@ -697,10 +697,10 @@ class TestInvocationVariants(object): lib = foo.mkdir("bar") lib.ensure("__init__.py") lib.join("test_bar.py").write( - "def test_bar(): pass\n" "def test_other(a_fixture):pass" + "def test_bar(): pass\ndef test_other(a_fixture):pass" ) lib.join("conftest.py").write( - "import pytest\n" "@pytest.fixture\n" "def a_fixture():pass" + "import pytest\n@pytest.fixture\ndef a_fixture():pass" ) d_local = testdir.mkdir("local") diff --git a/testing/logging/test_formatter.py b/testing/logging/test_formatter.py index 0348b215c..84ef4dd2f 100644 --- a/testing/logging/test_formatter.py +++ b/testing/logging/test_formatter.py @@ -26,10 +26,10 @@ def test_coloredlogformatter(): formatter = ColoredLevelFormatter(tw, logfmt) output = formatter.format(record) assert output == ( - "dummypath 10 " "\x1b[32mINFO \x1b[0m Test Message" + "dummypath 10 \x1b[32mINFO \x1b[0m Test Message" ) tw.hasmarkup = False formatter = ColoredLevelFormatter(tw, logfmt) output = formatter.format(record) - assert output == ("dummypath 10 " "INFO Test Message") + assert output == ("dummypath 10 INFO Test Message") diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 2304c4a50..29d3f7f6e 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -476,7 +476,7 @@ class TestPython(object): tnode.assert_attr( file="test_junit_prefixing.py", line="3", - classname="xyz.test_junit_prefixing." "TestHello", + classname="xyz.test_junit_prefixing.TestHello", name="test_hello", ) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 246f514b4..1c99c9f1e 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -282,7 +282,7 @@ class TestPDB(object): """ ) child = testdir.spawn_pytest( - "--show-capture=all --pdb " "-p no:logging %s" % p1 + "--show-capture=all --pdb -p no:logging %s" % p1 ) child.expect("get rekt") output = child.before.decode("utf8") From d1322570ddb8f1ec65924f990fe6d5c1e1ac6f36 Mon Sep 17 00:00:00 2001 From: Niklas JQ Date: Wed, 10 Oct 2018 19:45:07 +0200 Subject: [PATCH 2/7] Fix issue 4093 --- changelog/4093.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/4093.trivial.rst diff --git a/changelog/4093.trivial.rst b/changelog/4093.trivial.rst new file mode 100644 index 000000000..7efc66c68 --- /dev/null +++ b/changelog/4093.trivial.rst @@ -0,0 +1 @@ +The incorrect string literals are fixed. \ No newline at end of file From f36f9d26983d55d861968757e075b2f8d02e5a1c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 10 Oct 2018 20:48:20 +0200 Subject: [PATCH 3/7] tests: fix/clarify expect for Pdb `expect()` expects an regular expression, so "Pdb" is equivalent to "(Pdb)". But instead of escaping the parenthesis this patch removes them, to allow for matching "(Pdb++)", too. --- testing/test_pdb.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 246f514b4..bcc4f65cf 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -147,7 +147,7 @@ class TestPDB(object): child = testdir.spawn_pytest("--pdb %s" % p1) child.expect(".*def test_1") child.expect(".*i = 0") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -174,7 +174,7 @@ class TestPDB(object): """ ) child = testdir.spawn_pytest("--pdb %s" % p1) - child.expect("(Pdb)") + child.expect("Pdb") child.sendline("p self.filename") child.sendeof() rest = child.read().decode("utf8") @@ -209,7 +209,7 @@ class TestPDB(object): child = testdir.spawn_pytest("--pdb %s" % p1) child.expect("captured stdout") child.expect("get rekt") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -228,7 +228,7 @@ class TestPDB(object): child = testdir.spawn_pytest("--pdb %s" % p1) child.expect("captured stderr") child.expect("get rekt") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -243,7 +243,7 @@ class TestPDB(object): """ ) child = testdir.spawn_pytest("--pdb %s" % p1) - child.expect("(Pdb)") + child.expect("Pdb") output = child.before.decode("utf8") child.sendeof() assert "captured stdout" not in output @@ -266,7 +266,7 @@ class TestPDB(object): if showcapture in ("all", "log"): child.expect("captured log") child.expect("get rekt") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -287,7 +287,7 @@ class TestPDB(object): child.expect("get rekt") output = child.before.decode("utf8") assert "captured log" not in output - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -306,7 +306,7 @@ class TestPDB(object): child = testdir.spawn_pytest("--pdb %s" % p1) child.expect(".*def test_1") child.expect(".*pytest.raises.*globalfunc") - child.expect("(Pdb)") + child.expect("Pdb") child.sendline("globalfunc") child.expect(".*function") child.sendeof() @@ -322,7 +322,7 @@ class TestPDB(object): ) child = testdir.spawn_pytest("--pdb %s" % p1) # child.expect(".*import pytest.*") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() child.expect("1 error") self.flush(child) @@ -337,7 +337,7 @@ class TestPDB(object): p1 = testdir.makepyfile("def test_func(): pass") child = testdir.spawn_pytest("--pdb %s" % p1) # child.expect(".*import pytest.*") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() self.flush(child) @@ -355,7 +355,7 @@ class TestPDB(object): child = testdir.spawn_pytest(str(p1)) child.expect("test_1") child.expect("x = 3") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf-8") assert "1 failed" in rest @@ -373,7 +373,7 @@ class TestPDB(object): ) child = testdir.spawn_pytest(str(p1)) child.expect("test_1") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -448,10 +448,10 @@ class TestPDB(object): """ ) child = testdir.spawn_pytest("--doctest-modules --pdb %s" % p1) - child.expect("(Pdb)") + child.expect("Pdb") child.sendline("i") child.expect("0") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -474,7 +474,7 @@ class TestPDB(object): child = testdir.spawn_pytest(str(p1)) child.expect("test_1") child.expect("x = 3") - child.expect("(Pdb)") + child.expect("Pdb") child.sendline("c") child.expect("x = 4") child.sendeof() @@ -690,7 +690,7 @@ class TestDebuggingBreakpoints(object): ) child = testdir.spawn_pytest(str(p1)) child.expect("test_1") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -710,7 +710,7 @@ class TestDebuggingBreakpoints(object): ) child = testdir.spawn_pytest(str(p1)) child.expect("test_1") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -728,7 +728,7 @@ class TestTraceOption: ) child = testdir.spawn_pytest("--trace " + str(p1)) child.expect("test_1") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 passed" in rest @@ -747,7 +747,7 @@ class TestTraceOption: ) child = testdir.spawn_pytest("--trace " + str(p1)) child.expect("is_equal") - child.expect("(Pdb)") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 passed" in rest From be511c1a054b718b839dc847001ea50262c834b1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 10 Oct 2018 20:49:45 +0200 Subject: [PATCH 4/7] tests: add missing expect before sendeof for pdbpp With pdb++ this additional `expect` is required, otherwise `sendeof()` will block forever. --- testing/test_pdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index bcc4f65cf..da75a19a7 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -477,6 +477,7 @@ class TestPDB(object): child.expect("Pdb") child.sendline("c") child.expect("x = 4") + child.expect("Pdb") child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest @@ -495,6 +496,7 @@ class TestPDB(object): ) child = testdir.spawn("{} {}".format(sys.executable, p1)) child.expect("x = 5") + child.expect("Pdb") child.sendeof() self.flush(child) @@ -511,6 +513,7 @@ class TestPDB(object): ) child = testdir.spawn_pytest(str(p1)) child.expect("x = 5") + child.expect("Pdb") child.sendeof() self.flush(child) From c9a85b0e78e744e2101473d313f7b50e2ecc408f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 10 Oct 2018 19:53:21 -0300 Subject: [PATCH 5/7] Fix linting --- changelog/4093.trivial.rst | 2 +- doc/en/example/assertion/failure_demo.py | 6 +++--- src/_pytest/terminal.py | 4 +--- testing/test_pdb.py | 4 +--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/changelog/4093.trivial.rst b/changelog/4093.trivial.rst index 7efc66c68..cbfbeb00d 100644 --- a/changelog/4093.trivial.rst +++ b/changelog/4093.trivial.rst @@ -1 +1 @@ -The incorrect string literals are fixed. \ No newline at end of file +Fixed formatting of string literals in internal tests. diff --git a/doc/en/example/assertion/failure_demo.py b/doc/en/example/assertion/failure_demo.py index 5dff265a5..ae2f5acb2 100644 --- a/doc/en/example/assertion/failure_demo.py +++ b/doc/en/example/assertion/failure_demo.py @@ -245,9 +245,9 @@ class TestCustomAssertMsg(object): a = 1 b = 2 - assert A.a == b, ( - "A.a appears not to be b\nor does not appear to be b\none of those" - ) + assert ( + A.a == b + ), "A.a appears not to be b\nor does not appear to be b\none of those" def test_custom_repr(self): class JSON(object): diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a7a45da57..f4dbbe61a 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -835,9 +835,7 @@ def repr_pythonversion(v=None): def build_summary_stats_line(stats): - keys = ( - "failed passed skipped deselected xfailed xpassed warnings error" - ).split() + keys = ("failed passed skipped deselected xfailed xpassed warnings error").split() unknown_key_seen = False for key in stats.keys(): if key not in keys: diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 1c99c9f1e..2c73963fa 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -281,9 +281,7 @@ class TestPDB(object): assert False """ ) - child = testdir.spawn_pytest( - "--show-capture=all --pdb -p no:logging %s" % p1 - ) + child = testdir.spawn_pytest("--show-capture=all --pdb -p no:logging %s" % p1) child.expect("get rekt") output = child.before.decode("utf8") assert "captured log" not in output From dbaa9464ba3a3fd2b8ef9b31c795f99740048b1f Mon Sep 17 00:00:00 2001 From: Jose Carlos Menezes Date: Fri, 12 Oct 2018 09:43:00 -0300 Subject: [PATCH 6/7] Update usefixtures documentation Clarifying that it can't be used with fixture functions --- changelog/3713.doc.rst | 1 + doc/en/reference.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/3713.doc.rst diff --git a/changelog/3713.doc.rst b/changelog/3713.doc.rst new file mode 100644 index 000000000..c1d6b51b8 --- /dev/null +++ b/changelog/3713.doc.rst @@ -0,0 +1 @@ +Update usefixtures documentation to clarify that it can't be used with fixture functions. diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 0c0fdff01..1537efc61 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -178,7 +178,7 @@ Mark a test function as using the given fixture names. .. warning:: - This mark can be used with *test functions* only, having no affect when applied + This mark has no effect when applied to a **fixture** function. .. py:function:: pytest.mark.usefixtures(*names) From 2dc619cbf471d579f05edb2141963aa3316b69a9 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 12 Oct 2018 11:57:40 -0300 Subject: [PATCH 7/7] Run docs, doctesting and linting in the same environment to save some CI time --- .travis.yml | 4 +--- appveyor.yml | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index a319c0922..3936e599b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,6 @@ env: - TOXENV=py36-numpy - TOXENV=py36-pluggymaster PYTEST_NO_COVERAGE=1 - TOXENV=py27-nobyte - - TOXENV=doctesting - - TOXENV=docs PYTEST_NO_COVERAGE=1 jobs: include: @@ -61,7 +59,7 @@ jobs: env: TOXENV=py27 - env: TOXENV=py34 - env: TOXENV=py36 - - env: TOXENV=linting PYTEST_NO_COVERAGE=1 + - env: TOXENV=linting,docs,doctesting PYTEST_NO_COVERAGE=1 - stage: deploy python: '3.6' diff --git a/appveyor.yml b/appveyor.yml index 7e2c16561..efc880638 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: matrix: - - TOXENV: "linting" + - TOXENV: "linting,docs,doctesting" PYTEST_NO_COVERAGE: "1" - TOXENV: "py27" - TOXENV: "py34" @@ -20,11 +20,8 @@ environment: - TOXENV: "py36-pluggymaster" PYTEST_NO_COVERAGE: "1" - TOXENV: "py27-nobyte" - - TOXENV: "doctesting" - TOXENV: "py36-freeze" PYTEST_NO_COVERAGE: "1" - - TOXENV: "docs" - PYTEST_NO_COVERAGE: "1" install: - echo Installed Pythons