From a3b69d9d837a2c289cff88ba0171243a77ad22ae Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 16 Oct 2021 01:57:12 +0300 Subject: [PATCH] Remove py version printing, traceback filtering, freezing Not so important anymore, and makes it easier to remove the py dependency. --- src/_pytest/_code/code.py | 3 --- src/_pytest/freeze_support.py | 4 +--- src/_pytest/helpconfig.py | 7 ++----- src/_pytest/terminal.py | 5 ++--- testing/acceptance_test.py | 29 +++-------------------------- testing/test_helpconfig.py | 2 +- testing/test_mark.py | 5 ++--- testing/test_terminal.py | 7 ++----- 8 files changed, 13 insertions(+), 49 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 7da5cb3d1..b19ee7c64 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -1240,7 +1240,6 @@ _PLUGGY_DIR = Path(pluggy.__file__.rstrip("oc")) if _PLUGGY_DIR.name == "__init__.py": _PLUGGY_DIR = _PLUGGY_DIR.parent _PYTEST_DIR = Path(_pytest.__file__).parent -_PY_DIR = Path(__import__("py").__file__).parent def filter_traceback(entry: TracebackEntry) -> bool: @@ -1268,7 +1267,5 @@ def filter_traceback(entry: TracebackEntry) -> bool: return False if _PYTEST_DIR in parents: return False - if _PY_DIR in parents: - return False return True diff --git a/src/_pytest/freeze_support.py b/src/_pytest/freeze_support.py index 69b7d59ff..9f8ea231f 100644 --- a/src/_pytest/freeze_support.py +++ b/src/_pytest/freeze_support.py @@ -9,11 +9,9 @@ from typing import Union def freeze_includes() -> List[str]: """Return a list of module names used by pytest that should be included by cx_freeze.""" - import py import _pytest - result = list(_iter_all_modules(py)) - result += list(_iter_all_modules(_pytest)) + result = list(_iter_all_modules(_pytest)) return result diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py index e3739ce93..aca2cd391 100644 --- a/src/_pytest/helpconfig.py +++ b/src/_pytest/helpconfig.py @@ -6,8 +6,6 @@ from typing import List from typing import Optional from typing import Union -import py - import pytest from _pytest.config import Config from _pytest.config import ExitCode @@ -108,11 +106,10 @@ def pytest_cmdline_parse(): path = config.option.debug debugfile = open(path, "w") debugfile.write( - "versions pytest-%s, py-%s, " + "versions pytest-%s, " "python-%s\ncwd=%s\nargs=%s\n\n" % ( pytest.__version__, - py.__version__, ".".join(map(str, sys.version_info)), os.getcwd(), config.invocation_params.args, @@ -249,7 +246,7 @@ def getpluginversioninfo(config: Config) -> List[str]: def pytest_report_header(config: Config) -> List[str]: lines = [] if config.option.debug or config.option.traceconfig: - lines.append(f"using: pytest-{pytest.__version__} pylib-{py.__version__}") + lines.append(f"using: pytest-{pytest.__version__}") verinfo = getpluginversioninfo(config) if verinfo: diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index b34e2e2a8..8c5be3b78 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -29,7 +29,6 @@ from typing import Union import attr import pluggy -import py import _pytest._version from _pytest import nodes @@ -704,8 +703,8 @@ class TerminalReporter: if pypy_version_info: verinfo = ".".join(map(str, pypy_version_info[:3])) msg += f"[pypy-{verinfo}-{pypy_version_info[3]}]" - msg += ", pytest-{}, py-{}, pluggy-{}".format( - _pytest._version.version, py.__version__, pluggy.__version__ + msg += ", pytest-{}, pluggy-{}".format( + _pytest._version.version, pluggy.__version__ ) if ( self.verbosity > 0 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index e8a9ec4b8..30a507686 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -3,7 +3,6 @@ import sys import types import attr -import py import pytest from _pytest.compat import importlib_metadata @@ -515,28 +514,10 @@ class TestInvocationVariants: assert result.ret == 0 def test_pydoc(self, pytester: Pytester) -> None: - for name in ("py.test", "pytest"): - result = pytester.runpython_c(f"import {name};help({name})") - assert result.ret == 0 - s = result.stdout.str() - assert "MarkGenerator" in s - - def test_import_star_py_dot_test(self, pytester: Pytester) -> None: - p = pytester.makepyfile( - """ - from py.test import * - #collect - #cmdline - #Item - # assert collect.Item is Item - # assert collect.Collector is Collector - main - skip - xfail - """ - ) - result = pytester.runpython(p) + result = pytester.runpython_c("import pytest;help(pytest)") assert result.ret == 0 + s = result.stdout.str() + assert "MarkGenerator" in s def test_import_star_pytest(self, pytester: Pytester) -> None: p = pytester.makepyfile( @@ -585,10 +566,6 @@ class TestInvocationVariants: assert res.ret == 0 res.stdout.fnmatch_lines(["*1 passed*"]) - def test_equivalence_pytest_pydottest(self) -> None: - # Type ignored because `py.test` is not and will not be typed. - assert pytest.main == py.test.cmdline.main # type: ignore[attr-defined] - def test_invoke_with_invalid_type(self) -> None: with pytest.raises( TypeError, match="expected to be a list of strings, got: '-h'" diff --git a/testing/test_helpconfig.py b/testing/test_helpconfig.py index dd77b55b5..44c2c9295 100644 --- a/testing/test_helpconfig.py +++ b/testing/test_helpconfig.py @@ -105,7 +105,7 @@ def test_hookvalidation_optional(pytester: Pytester) -> None: def test_traceconfig(pytester: Pytester) -> None: result = pytester.runpytest("--traceconfig") - result.stdout.fnmatch_lines(["*using*pytest*py*", "*active plugins*"]) + result.stdout.fnmatch_lines(["*using*pytest*", "*active plugins*"]) def test_debug(pytester: Pytester) -> None: diff --git a/testing/test_mark.py b/testing/test_mark.py index 77991f9e2..ce65e7d56 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -15,9 +15,8 @@ from _pytest.pytester import Pytester class TestMark: @pytest.mark.parametrize("attr", ["mark", "param"]) - @pytest.mark.parametrize("modulename", ["py.test", "pytest"]) - def test_pytest_exists_in_namespace_all(self, attr: str, modulename: str) -> None: - module = sys.modules[modulename] + def test_pytest_exists_in_namespace_all(self, attr: str) -> None: + module = sys.modules["pytest"] assert attr in module.__all__ # type: ignore def test_pytest_mark_notcallable(self) -> None: diff --git a/testing/test_terminal.py b/testing/test_terminal.py index c8834b545..0f14c4d0c 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -12,7 +12,6 @@ from typing import List from typing import Tuple import pluggy -import py import _pytest.config import _pytest.terminal @@ -800,12 +799,11 @@ class TestTerminalFunctional: result.stdout.fnmatch_lines( [ "*===== test session starts ====*", - "platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s" + "platform %s -- Python %s*pytest-%s**pluggy-%s" % ( sys.platform, verinfo, pytest.__version__, - py.__version__, pluggy.__version__, ), "*test_header_trailer_info.py .*", @@ -828,12 +826,11 @@ class TestTerminalFunctional: result = pytester.runpytest("--no-header") verinfo = ".".join(map(str, sys.version_info[:3])) result.stdout.no_fnmatch_line( - "platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s" + "platform %s -- Python %s*pytest-%s**pluggy-%s" % ( sys.platform, verinfo, pytest.__version__, - py.__version__, pluggy.__version__, ) )