Skip to content

Commit

Permalink
Merge pull request #9460 from hugovk/rm-3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 30, 2021
2 parents b9663fe + 1fd3601 commit 325744e
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ template = "changelog/_template.rst"
showcontent = true

[tool.black]
target-version = ['py36']
target-version = ['py37']
3 changes: 0 additions & 3 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ def find_spec(
spec is None
# this is a namespace package (without `__init__.py`)
# there's nothing to rewrite there
# python3.6: `namespace`
# python3.7+: `None`
or spec.origin == "namespace"
or spec.origin is None
# we can only rewrite source files
or not isinstance(spec.loader, importlib.machinery.SourceFileLoader)
Expand Down
6 changes: 3 additions & 3 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def _colorama_workaround() -> None:
pass


def _py36_windowsconsoleio_workaround(stream: TextIO) -> None:
"""Workaround for Windows Unicode console handling on Python>=3.6.
def _windowsconsoleio_workaround(stream: TextIO) -> None:
"""Workaround for Windows Unicode console handling.
Python 3.6 implemented Unicode console handling for Windows. This works
by reading/writing to the raw console handle using
Expand Down Expand Up @@ -128,7 +128,7 @@ def _reopen_stdio(f, mode):
def pytest_load_initial_conftests(early_config: Config):
ns = early_config.known_args_namespace
if ns.capture == "fd":
_py36_windowsconsoleio_workaround(sys.stdout)
_windowsconsoleio_workaround(sys.stdout)
_colorama_workaround()
pluginmanager = early_config.pluginmanager
capman = CaptureManager(ns.capture)
Expand Down
4 changes: 1 addition & 3 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
for basecls in self.obj.__mro__:
dicts.append(basecls.__dict__)

# In each class, nodes should be definition ordered. Since Python 3.6,
# In each class, nodes should be definition ordered.
# __dict__ is definition ordered.
seen: Set[str] = set()
dict_values: List[List[Union[nodes.Item, nodes.Collector]]] = []
Expand Down Expand Up @@ -894,8 +894,6 @@ class InstanceDummy:
pass


# Note: module __getattr__ only works on Python>=3.7. Unfortunately
# we can't provide this deprecation warning on Python 3.6.
def __getattr__(name: str) -> object:
if name == "Instance":
warnings.warn(INSTANCE_COLLECTOR, 2)
Expand Down
4 changes: 0 additions & 4 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ def test_node_ctor_fspath_argument_is_deprecated(pytester: Pytester) -> None:
)


@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="This deprecation can only be emitted on python>=3.7",
)
def test_importing_instance_is_deprecated(pytester: Pytester) -> None:
with pytest.warns(
pytest.PytestDeprecationWarning,
Expand Down
3 changes: 0 additions & 3 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,6 @@ def test_read_pyc(self, tmp_path: Path) -> None:

assert _read_pyc(source, pyc) is None # no error

@pytest.mark.skipif(
sys.version_info < (3, 7), reason="Only the Python 3.7 format for simplicity"
)
def test_read_pyc_more_invalid(self, tmp_path: Path) -> None:
from _pytest.assertion.rewrite import _read_pyc

Expand Down
8 changes: 4 additions & 4 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,19 +1433,19 @@ def test_capattr():
not sys.platform.startswith("win"),
reason="only on windows",
)
def test_py36_windowsconsoleio_workaround_non_standard_streams() -> None:
def test_windowsconsoleio_workaround_non_standard_streams() -> None:
"""
Ensure _py36_windowsconsoleio_workaround function works with objects that
Ensure _windowsconsoleio_workaround function works with objects that
do not implement the full ``io``-based stream protocol, for example execnet channels (#2666).
"""
from _pytest.capture import _py36_windowsconsoleio_workaround
from _pytest.capture import _windowsconsoleio_workaround

class DummyStream:
def write(self, s):
pass

stream = cast(TextIO, DummyStream())
_py36_windowsconsoleio_workaround(stream)
_windowsconsoleio_workaround(stream)


def test_dontreadfrominput_has_encoding(pytester: Pytester) -> None:
Expand Down
2 changes: 1 addition & 1 deletion testing/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_is_generator_async_gen_syntax(pytester: Pytester) -> None:
pytester.makepyfile(
"""
from _pytest.compat import is_generator
def test_is_generator_py36():
def test_is_generator():
async def foo():
yield
await foo()
Expand Down
113 changes: 53 additions & 60 deletions testing/test_error_diffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
See https://github.com/pytest-dev/pytest/issues/3333 for details.
"""
import sys

import pytest
from _pytest.pytester import Pytester

Expand Down Expand Up @@ -210,68 +208,63 @@ def test_this():
""",
id='Test "not in" string',
),
]
if sys.version_info[:2] >= (3, 7):
TESTCASES.extend(
[
pytest.param(
"""
from dataclasses import dataclass
pytest.param(
"""
from dataclasses import dataclass
@dataclass
class A:
a: int
b: str
@dataclass
class A:
a: int
b: str
def test_this():
result = A(1, 'spam')
expected = A(2, 'spam')
assert result == expected
""",
"""
> assert result == expected
E AssertionError: assert A(a=1, b='spam') == A(a=2, b='spam')
E Matching attributes:
E ['b']
E Differing attributes:
E ['a']
E Drill down into differing attribute a:
E a: 1 != 2
E +1
E -2
""",
id="Compare data classes",
),
pytest.param(
"""
import attr
def test_this():
result = A(1, 'spam')
expected = A(2, 'spam')
assert result == expected
""",
"""
> assert result == expected
E AssertionError: assert A(a=1, b='spam') == A(a=2, b='spam')
E Matching attributes:
E ['b']
E Differing attributes:
E ['a']
E Drill down into differing attribute a:
E a: 1 != 2
E +1
E -2
""",
id="Compare data classes",
),
pytest.param(
"""
import attr
@attr.s(auto_attribs=True)
class A:
a: int
b: str
@attr.s(auto_attribs=True)
class A:
a: int
b: str
def test_this():
result = A(1, 'spam')
expected = A(1, 'eggs')
assert result == expected
""",
"""
> assert result == expected
E AssertionError: assert A(a=1, b='spam') == A(a=1, b='eggs')
E Matching attributes:
E ['a']
E Differing attributes:
E ['b']
E Drill down into differing attribute b:
E b: 'spam' != 'eggs'
E - eggs
E + spam
""",
id="Compare attrs classes",
),
]
)
def test_this():
result = A(1, 'spam')
expected = A(1, 'eggs')
assert result == expected
""",
"""
> assert result == expected
E AssertionError: assert A(a=1, b='spam') == A(a=1, b='eggs')
E Matching attributes:
E ['a']
E Differing attributes:
E ['b']
E Drill down into differing attribute b:
E b: 'spam' != 'eggs'
E - eggs
E + spam
""",
id="Compare attrs classes",
),
]


@pytest.mark.parametrize("code, expected", TESTCASES)
Expand Down
1 change: 0 additions & 1 deletion testing/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ def test_samefile_false_negatives(tmp_path: Path, monkeypatch: MonkeyPatch) -> N


class TestImportLibMode:
@pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses in Python3.7+")
def test_importmode_importlib_with_dataclass(self, tmp_path: Path) -> None:
"""Ensure that importlib mode works with a module containing dataclasses (#7856)."""
fn = tmp_path.joinpath("_src/tests/test_dataclass.py")
Expand Down

0 comments on commit 325744e

Please sign in to comment.