From aa79b1c00c63a0cbba756adec2b2e1e51da82a45 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 29 Aug 2019 09:48:58 -0700 Subject: [PATCH] [4.6] fixes for python4 --- changelog/5801.trivial.rst | 1 + src/_pytest/pastebin.py | 2 +- src/_pytest/pytester.py | 2 +- testing/acceptance_test.py | 2 +- testing/python/raises.py | 2 +- testing/test_monkeypatch.py | 4 ++-- testing/test_pastebin.py | 4 ++-- testing/test_warnings.py | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 changelog/5801.trivial.rst diff --git a/changelog/5801.trivial.rst b/changelog/5801.trivial.rst new file mode 100644 index 000000000..80b1f8238 --- /dev/null +++ b/changelog/5801.trivial.rst @@ -0,0 +1 @@ +Fixes python version checks (detected by ``flake8-2020``) in case python4 becomes a thing. diff --git a/src/_pytest/pastebin.py b/src/_pytest/pastebin.py index 3f4171207..41576a615 100644 --- a/src/_pytest/pastebin.py +++ b/src/_pytest/pastebin.py @@ -79,7 +79,7 @@ def create_new_paste(contents): params = { "code": contents, - "lexer": "python3" if sys.version_info[0] == 3 else "python", + "lexer": "python3" if sys.version_info[0] >= 3 else "python", "expiry": "1week", } url = "https://bpaste.net" diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 605451630..f1d739c99 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1124,7 +1124,7 @@ class Testdir(object): if timeout is None: ret = popen.wait() - elif six.PY3: + elif not six.PY2: try: ret = popen.wait(timeout) except subprocess.TimeoutExpired: diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 7016cf13b..4079cddb6 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -223,7 +223,7 @@ class TestGeneralUsage(object): "conftest.py:2: in foo", " import qwerty", "E {}: No module named {q}qwerty{q}".format( - exc_name, q="'" if six.PY3 else "" + exc_name, q="" if six.PY2 else "'" ), ] ) diff --git a/testing/python/raises.py b/testing/python/raises.py index 9cd3ec717..fa25d9f73 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -289,7 +289,7 @@ class TestUnicodeHandling: success = dummy_context_manager py2_only = pytest.mark.skipif( - six.PY3, reason="bytes in raises only supported in Python 2" + not six.PY2, reason="bytes in raises only supported in Python 2" ) @pytest.mark.parametrize( diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 9b2f45502..961c57e06 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -209,7 +209,7 @@ class TestEnvironWarnings(object): VAR_NAME = u"PYTEST_INTERNAL_MY_VAR" - @pytest.mark.skipif(six.PY3, reason="Python 2 only test") + @pytest.mark.skipif(not six.PY2, reason="Python 2 only test") def test_setenv_unicode_key(self, monkeypatch): with pytest.warns( pytest.PytestWarning, @@ -217,7 +217,7 @@ class TestEnvironWarnings(object): ): monkeypatch.setenv(self.VAR_NAME, "2") - @pytest.mark.skipif(six.PY3, reason="Python 2 only test") + @pytest.mark.skipif(not six.PY2, reason="Python 2 only test") def test_delenv_unicode_key(self, monkeypatch): with pytest.warns( pytest.PytestWarning, diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py index 9491f6d90..bac8f9802 100644 --- a/testing/test_pastebin.py +++ b/testing/test_pastebin.py @@ -74,7 +74,7 @@ class TestPasteCapture(object): """ ) result = testdir.runpytest("--pastebin=all") - if sys.version_info[0] == 3: + if sys.version_info[0] >= 3: expected_msg = "*assert '☺' == 1*" else: expected_msg = "*assert '\\xe2\\x98\\xba' == 1*" @@ -126,7 +126,7 @@ class TestPaste(object): assert len(mocked_urlopen) == 1 url, data = mocked_urlopen[0] assert type(data) is bytes - lexer = "python3" if sys.version_info[0] == 3 else "python" + lexer = "python3" if sys.version_info[0] >= 3 else "python" assert url == "https://bpaste.net" assert "lexer=%s" % lexer in data.decode() assert "code=full-paste-contents" in data.decode() diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 092604d7d..65f57e024 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -569,7 +569,7 @@ class TestDeprecationWarningsByDefault: assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() -@pytest.mark.skipif(six.PY3, reason="Python 2 only issue") +@pytest.mark.skipif(not six.PY2, reason="Python 2 only issue") def test_infinite_loop_warning_against_unicode_usage_py2(testdir): """ We need to be careful when raising the warning about unicode usage with "warnings.warn"