diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1741136dfe0..89a9238ffa0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,12 +32,12 @@ repos: rev: v2.6.0 hooks: - id: reorder-python-imports - args: ['--application-directories=.:src', --py36-plus] + args: ['--application-directories=.:src', --py37-plus] - repo: https://github.com/asottile/pyupgrade rev: v2.29.1 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py37-plus] - repo: https://github.com/asottile/setup-cfg-fmt rev: v1.20.0 hooks: diff --git a/doc/en/how-to/skipping.rst b/doc/en/how-to/skipping.rst index 9b74628d59f..d95e194107d 100644 --- a/doc/en/how-to/skipping.rst +++ b/doc/en/how-to/skipping.rst @@ -84,14 +84,14 @@ It is also possible to skip the whole module using If you wish to skip something conditionally then you can use ``skipif`` instead. Here is an example of marking a test function to be skipped -when run on an interpreter earlier than Python3.6: +when run on an interpreter earlier than Python3.7: .. code-block:: python import sys - @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") + @pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher") def test_function(): ... diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 50b367e25ef..cacbe359b0c 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -293,9 +293,8 @@ def _write_pyc_fp( # import. However, there's little reason to deviate. fp.write(importlib.util.MAGIC_NUMBER) # https://www.python.org/dev/peps/pep-0552/ - if sys.version_info >= (3, 7): - flags = b"\x00\x00\x00\x00" - fp.write(flags) + flags = b"\x00\x00\x00\x00" + fp.write(flags) # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903) mtime = int(source_stat.st_mtime) & 0xFFFFFFFF size = source_stat.st_size & 0xFFFFFFFF diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 5af01eb7d95..3193a9a2293 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -4,7 +4,7 @@ import inspect import os import sys -from contextlib import contextmanager +from contextlib import nullcontext as nullcontext # noqa: F401 from inspect import Parameter from inspect import signature from pathlib import Path @@ -186,16 +186,6 @@ def getfuncargnames( return arg_names -if sys.version_info < (3, 7): - - @contextmanager - def nullcontext(): - yield - -else: - from contextlib import nullcontext as nullcontext # noqa: F401 - - def get_default_arg_names(function: Callable[..., Any]) -> Tuple[str, ...]: # Note: this code intentionally mirrors the code at the beginning of # getfuncargnames, to get the arguments which were excluded from its result diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 31ad8301076..c99d3aaa05b 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -2,7 +2,6 @@ import logging import os import re -import sys from contextlib import contextmanager from io import StringIO from pathlib import Path @@ -622,16 +621,7 @@ def set_log_path(self, fname: str) -> None: fpath.parent.mkdir(exist_ok=True, parents=True) stream = fpath.open(mode="w", encoding="UTF-8") - if sys.version_info >= (3, 7): - old_stream = self.log_file_handler.setStream(stream) - else: - old_stream = self.log_file_handler.stream - self.log_file_handler.acquire() - try: - self.log_file_handler.flush() - self.log_file_handler.stream = stream - finally: - self.log_file_handler.release() + old_stream = self.log_file_handler.setStream(stream) if old_stream: # https://github.com/python/typeshed/pull/5663 old_stream.close() # type:ignore[attr-defined] diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 42e71ff917e..38eaef2fcc6 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -128,7 +128,7 @@ def get_open_files(self) -> List[Tuple[str, str]]: stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, check=True, - universal_newlines=True, + text=True, ).stdout def isopen(line: str) -> bool: diff --git a/testing/test_debugging.py b/testing/test_debugging.py index a822bb57f58..f3c271710d2 100644 --- a/testing/test_debugging.py +++ b/testing/test_debugging.py @@ -913,8 +913,7 @@ def test_foo(): class TestDebuggingBreakpoints: def test_supports_breakpoint_module_global(self) -> None: """Test that supports breakpoint global marks on Python 3.7+.""" - if sys.version_info >= (3, 7): - assert SUPPORTS_BREAKPOINT_BUILTIN is True + assert SUPPORTS_BREAKPOINT_BUILTIN is True @pytest.mark.skipif( not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin" diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 28529d04378..992f49bc53c 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -295,7 +295,7 @@ def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, check=True, - universal_newlines=True, + text=True, ).stdout except (OSError, subprocess.CalledProcessError): pytest.skip("bash is not available")