Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ lint.ignore = [
"FA102", # Missing `from __future__ import annotations`, but uses PEP 585/604 syntax
# flynt ignore
"FLY002", # Consider an f-string instead of string join
# refurb ignore
"FURB157", # Verbose expression in `Decimal` constructor
"FURB188", # Prefer `str.removeprefix()` over conditionally replacing with slice
# flake8-implicit-str-concat ignore
"ISC004", # Unparenthesized implicit string concatenation in collection
# flake8-logging ignore
Expand Down Expand Up @@ -218,8 +215,6 @@ lint.ignore = [
# flake8-use-pathlib ignore
"PTH124", # `py.path` is in maintenance mode, use `pathlib` instead
"PTH210", # Invalid suffix passed to `.with_suffix()`
# flake8-return ignore
"RET501", # Do not explicitly `return None` in function if it is the only possible return value
# ruff ignore
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF061", # Use context-manager form of `pytest.raises()`
Expand All @@ -240,9 +235,6 @@ lint.ignore = [
"SIM211", # Use `not ...` instead of `False if ... else True`
"SIM222", # Use the simplified expression instead of `... or True`
"SIM223", # Use the simplified expression instead of `... and False`
"SIM905", # Consider using a list literal instead of `str.split()`
# flake8-type-checking ignore
"TC005", # Found empty type-checking block
# tryceratops ignore
"TRY002", # Create your own exception
"TRY004", # Prefer `TypeError` exception for invalid type
Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,7 @@ def _get_single_subexc(
text = "".join(lines)
text = text.rstrip()
if tryshort:
if text.startswith(self._striptext):
text = text[len(self._striptext) :]
text = text.removeprefix(self._striptext)
return text

def errisinstance(self, exc: EXCEPTION_OR_MORE) -> bool:
Expand Down
6 changes: 2 additions & 4 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,14 @@ def append_error(self, report: TestReport) -> None:
def append_skipped(self, report: TestReport) -> None:
if hasattr(report, "wasxfail"):
xfailreason = report.wasxfail
if xfailreason.startswith("reason: "):
xfailreason = xfailreason[8:]
xfailreason = xfailreason.removeprefix("reason: ")
xfailreason = bin_xml_escape(xfailreason)
skipped = ET.Element("skipped", type="pytest.xfail", message=xfailreason)
self.append(skipped)
else:
assert isinstance(report.longrepr, tuple)
filename, lineno, skipreason = report.longrepr
if skipreason.startswith("Skipped: "):
skipreason = skipreason[9:]
skipreason = skipreason.removeprefix("Skipped: ")
details = f"{filename}:{lineno}: {skipreason}"

skipped = ET.Element(
Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ def import_path(

if module_file.endswith((".pyc", ".pyo")):
module_file = module_file[:-1]
if module_file.endswith(os.sep + "__init__.py"):
module_file = module_file[: -(len(os.sep + "__init__.py"))]
module_file = module_file.removesuffix(os.sep + "__init__.py")

try:
is_same = _is_same(str(path), module_file)
Expand Down
12 changes: 4 additions & 8 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,8 +1294,7 @@ def summary_stats(self) -> None:

if display_sep:
markup_for_end_sep = self._tw.markup("", **main_markup)
if markup_for_end_sep.endswith("\x1b[0m"):
markup_for_end_sep = markup_for_end_sep[:-4]
markup_for_end_sep = markup_for_end_sep.removesuffix("\x1b[0m")
fullwidth += len(markup_for_end_sep)
msg += markup_for_end_sep

Expand Down Expand Up @@ -1365,8 +1364,7 @@ def show_skipped_folded(lines: list[str]) -> None:
markup_word = self._tw.markup(verbose_word, **verbose_markup)
prefix = "Skipped: "
for num, fspath, lineno, reason in fskips:
if reason.startswith(prefix):
reason = reason[len(prefix) :]
reason = reason.removeprefix(prefix)
if lineno is not None:
lines.append(f"{markup_word} [{num}] {fspath}:{lineno}: {reason}")
else:
Expand Down Expand Up @@ -1659,8 +1657,7 @@ def _plugin_nameversions(plugininfo) -> list[str]:
# Gets us name and version!
name = f"{dist.project_name}-{dist.version}"
# Questionable convenience, but it keeps things short.
if name.startswith("pytest-"):
name = name[7:]
name = name.removeprefix("pytest-")
# We decided to print python package names they can have more than one plugin.
if name not in values:
values.append(name)
Expand Down Expand Up @@ -1706,8 +1703,7 @@ def _get_raw_skip_reason(report: TestReport) -> str:
"""
if hasattr(report, "wasxfail"):
reason = report.wasxfail
if reason.startswith("reason: "):
reason = reason[len("reason: ") :]
reason = reason.removeprefix("reason: ")
return reason
else:
assert report.skipped
Expand Down
4 changes: 0 additions & 4 deletions src/_pytest/threadexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import threading
import traceback
from typing import NamedTuple
from typing import TYPE_CHECKING
import warnings

from _pytest.config import Config
Expand All @@ -17,9 +16,6 @@
import pytest


if TYPE_CHECKING:
pass

if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _register_unittest_setup_method_fixture(self, cls: type) -> None:
setup = getattr(cls, "setup_method", None)
teardown = getattr(cls, "teardown_method", None)
if setup is None and teardown is None:
return None
return

def unittest_setup_method_fixture(
request: FixtureRequest,
Expand Down
4 changes: 0 additions & 4 deletions src/_pytest/unraisableexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
import traceback
from typing import NamedTuple
from typing import TYPE_CHECKING
import warnings

from _pytest.config import Config
Expand All @@ -17,9 +16,6 @@
import pytest


if TYPE_CHECKING:
pass

if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup

Expand Down
4 changes: 2 additions & 2 deletions testing/python/approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def test_list(self):

def test_list_decimal(self):
actual = [Decimal("1.000001"), Decimal("2.000001")]
expected = [Decimal("1"), Decimal("2")]
expected = [Decimal(1), Decimal(2)]

assert actual == approx(expected)

Expand Down Expand Up @@ -713,7 +713,7 @@ def test_dict_decimal(self):
actual = {"a": Decimal("1.000001"), "b": Decimal("2.000001")}
# Dictionaries became ordered in python3.6, so switch up the order here
# to make sure it doesn't matter.
expected = {"b": Decimal("2"), "a": Decimal("1")}
expected = {"b": Decimal(2), "a": Decimal(1)}

assert actual == approx(expected)

Expand Down
10 changes: 5 additions & 5 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4628,7 +4628,7 @@ def test_func(m1):
items, _ = pytester.inline_genitems()
assert isinstance(items[0], Function)
request = TopRequest(items[0], _ispytest=True)
assert request.fixturenames == "m1 f1".split()
assert request.fixturenames == ["m1", "f1"]

def test_func_closure_with_native_fixtures(self, pytester: Pytester) -> None:
"""Sanity check that verifies the order returned by the closures and the
Expand Down Expand Up @@ -4717,7 +4717,7 @@ def test_func(f1, m1):
items, _ = pytester.inline_genitems()
assert isinstance(items[0], Function)
request = TopRequest(items[0], _ispytest=True)
assert request.fixturenames == "m1 f1".split()
assert request.fixturenames == ["m1", "f1"]

def test_func_closure_scopes_reordered(self, pytester: Pytester) -> None:
"""Test ensures that fixtures are ordered by scope regardless of the order of the parameters, although
Expand Down Expand Up @@ -4751,7 +4751,7 @@ def test_func(self, f2, f1, c1, m1, s1):
items, _ = pytester.inline_genitems()
assert isinstance(items[0], Function)
request = TopRequest(items[0], _ispytest=True)
assert request.fixturenames == "s1 m1 c1 f2 f1".split()
assert request.fixturenames == ["s1", "m1", "c1", "f2", "f1"]

def test_func_closure_same_scope_closer_root_first(
self, pytester: Pytester
Expand Down Expand Up @@ -4794,7 +4794,7 @@ def test_func(m_test, f1):
items, _ = pytester.inline_genitems()
assert isinstance(items[0], Function)
request = TopRequest(items[0], _ispytest=True)
assert request.fixturenames == "p_sub m_conf m_sub m_test f1".split()
assert request.fixturenames == ["p_sub", "m_conf", "m_sub", "m_test", "f1"]

def test_func_closure_all_scopes_complex(self, pytester: Pytester) -> None:
"""Complex test involving all scopes and mixing autouse with normal fixtures"""
Expand Down Expand Up @@ -4839,7 +4839,7 @@ def test_func(self, f2, f1, m2):
items, _ = pytester.inline_genitems()
assert isinstance(items[0], Function)
request = TopRequest(items[0], _ispytest=True)
assert request.fixturenames == "s1 p1 m1 m2 c1 f2 f1".split()
assert request.fixturenames == ["s1", "p1", "m1", "m2", "c1", "f2", "f1"]

def test_parametrized_package_scope_reordering(self, pytester: Pytester) -> None:
"""A parameterized package-scoped fixture correctly reorders items to
Expand Down
2 changes: 1 addition & 1 deletion testing/test_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ def test_remove_dir_prefix(self):

ffc = FastFilesCompleter()
fc = FilesCompleter()
for x in "/usr/".split():
for x in ["/usr/"]:
assert not equal_with_bash(x, ffc, fc, out=sys.stdout)
2 changes: 1 addition & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,7 +2467,7 @@ def test_with_config_also_in_parent_directory(


class TestOverrideIniArgs:
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
@pytest.mark.parametrize("name", ["setup.cfg", "tox.ini", "pytest.ini"])
def test_override_ini_names(self, pytester: Pytester, name: str) -> None:
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
pytester.path.joinpath(name).write_text(
Expand Down
4 changes: 2 additions & 2 deletions testing/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_doubledash_considered(pytester: Pytester) -> None:


def test_issue151_load_all_conftests(pytester: Pytester) -> None:
names = "code proj src".split()
names = ["code", "proj", "src"]
for name in names:
p = pytester.mkdir(name)
p.joinpath("conftest.py").touch()
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_conftestcutdir_inplace_considered(pytester: Pytester) -> None:
assert values[0].__file__.startswith(str(conf))


@pytest.mark.parametrize("name", "test tests whatever .dotdir".split())
@pytest.mark.parametrize("name", ["test", "tests", "whatever", ".dotdir"])
def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
sub = pytester.mkdir(name)
subconftest = sub.joinpath("conftest.py")
Expand Down