Skip to content

Commit 3d7cd77

Browse files
committed
Update syntax to Python3.7+.
1 parent 5599c5a commit 3d7cd77

File tree

8 files changed

+11
-33
lines changed

8 files changed

+11
-33
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ repos:
3232
rev: v2.6.0
3333
hooks:
3434
- id: reorder-python-imports
35-
args: ['--application-directories=.:src', --py36-plus]
35+
args: ['--application-directories=.:src', --py37-plus]
3636
- repo: https://github.com/asottile/pyupgrade
3737
rev: v2.29.1
3838
hooks:
3939
- id: pyupgrade
40-
args: [--py36-plus]
40+
args: [--py37-plus]
4141
- repo: https://github.com/asottile/setup-cfg-fmt
4242
rev: v1.20.0
4343
hooks:

doc/en/how-to/skipping.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ It is also possible to skip the whole module using
8484

8585
If you wish to skip something conditionally then you can use ``skipif`` instead.
8686
Here is an example of marking a test function to be skipped
87-
when run on an interpreter earlier than Python3.6:
87+
when run on an interpreter earlier than Python3.10:
8888

8989
.. code-block:: python
9090
9191
import sys
9292
9393
94-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
94+
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
9595
def test_function():
9696
...
9797

src/_pytest/assertion/rewrite.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,8 @@ def _write_pyc_fp(
293293
# import. However, there's little reason to deviate.
294294
fp.write(importlib.util.MAGIC_NUMBER)
295295
# https://www.python.org/dev/peps/pep-0552/
296-
if sys.version_info >= (3, 7):
297-
flags = b"\x00\x00\x00\x00"
298-
fp.write(flags)
296+
flags = b"\x00\x00\x00\x00"
297+
fp.write(flags)
299298
# as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
300299
mtime = int(source_stat.st_mtime) & 0xFFFFFFFF
301300
size = source_stat.st_size & 0xFFFFFFFF

src/_pytest/compat.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
import os
66
import sys
7-
from contextlib import contextmanager
7+
from contextlib import nullcontext as nullcontext # noqa: F401
88
from inspect import Parameter
99
from inspect import signature
1010
from pathlib import Path
@@ -186,16 +186,6 @@ def getfuncargnames(
186186
return arg_names
187187

188188

189-
if sys.version_info < (3, 7):
190-
191-
@contextmanager
192-
def nullcontext():
193-
yield
194-
195-
else:
196-
from contextlib import nullcontext as nullcontext # noqa: F401
197-
198-
199189
def get_default_arg_names(function: Callable[..., Any]) -> Tuple[str, ...]:
200190
# Note: this code intentionally mirrors the code at the beginning of
201191
# getfuncargnames, to get the arguments which were excluded from its result

src/_pytest/logging.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import os
55
import re
6-
import sys
76
from contextlib import contextmanager
87
from io import StringIO
98
from pathlib import Path
@@ -628,16 +627,7 @@ def set_log_path(self, fname: str) -> None:
628627

629628
# https://github.com/python/mypy/issues/11193
630629
stream: io.TextIOWrapper = fpath.open(mode="w", encoding="UTF-8") # type: ignore[assignment]
631-
if sys.version_info >= (3, 7):
632-
old_stream = self.log_file_handler.setStream(stream)
633-
else:
634-
old_stream = self.log_file_handler.stream
635-
self.log_file_handler.acquire()
636-
try:
637-
self.log_file_handler.flush()
638-
self.log_file_handler.stream = stream
639-
finally:
640-
self.log_file_handler.release()
630+
old_stream = self.log_file_handler.setStream(stream)
641631
if old_stream:
642632
old_stream.close()
643633

src/_pytest/pytester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_open_files(self) -> List[Tuple[str, str]]:
128128
stdout=subprocess.PIPE,
129129
stderr=subprocess.DEVNULL,
130130
check=True,
131-
universal_newlines=True,
131+
text=True,
132132
).stdout
133133

134134
def isopen(line: str) -> bool:

testing/test_debugging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,7 @@ def test_foo():
913913
class TestDebuggingBreakpoints:
914914
def test_supports_breakpoint_module_global(self) -> None:
915915
"""Test that supports breakpoint global marks on Python 3.7+."""
916-
if sys.version_info >= (3, 7):
917-
assert SUPPORTS_BREAKPOINT_BUILTIN is True
916+
assert SUPPORTS_BREAKPOINT_BUILTIN is True
918917

919918
@pytest.mark.skipif(
920919
not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin"

testing/test_parseopt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
295295
stdout=subprocess.PIPE,
296296
stderr=subprocess.DEVNULL,
297297
check=True,
298-
universal_newlines=True,
298+
text=True,
299299
).stdout
300300
except (OSError, subprocess.CalledProcessError):
301301
pytest.skip("bash is not available")

0 commit comments

Comments
 (0)