Skip to content

Commit b38edec

Browse files
authored
Merge pull request #7238 from bluetech/micro-optimizations-1
A few tiny micro-optimizations/simplifications
2 parents 4a1557f + f1f9c77 commit b38edec

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/_pytest/config/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import attr
2525
import py
26-
from packaging.version import Version
2726
from pluggy import HookimplMarker
2827
from pluggy import HookspecMarker
2928
from pluggy import PluginManager
@@ -1059,6 +1058,9 @@ def _checkversion(self):
10591058

10601059
minver = self.inicfg.get("minversion", None)
10611060
if minver:
1061+
# Imported lazily to improve start-up time.
1062+
from packaging.version import Version
1063+
10621064
if Version(minver) > Version(pytest.__version__):
10631065
raise pytest.UsageError(
10641066
"%s:%d: requires pytest-%s, actual pytest-%s'"

src/_pytest/nodes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,7 @@ def _check_initialpaths_for_relpath(session, fspath):
456456

457457

458458
class FSHookProxy:
459-
def __init__(
460-
self, fspath: py.path.local, pm: PytestPluginManager, remove_mods
461-
) -> None:
462-
self.fspath = fspath
459+
def __init__(self, pm: PytestPluginManager, remove_mods) -> None:
463460
self.pm = pm
464461
self.remove_mods = remove_mods
465462

@@ -510,7 +507,7 @@ def _gethookproxy(self, fspath: py.path.local):
510507
remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
511508
if remove_mods:
512509
# one or more conftests are not in use at this fspath
513-
proxy = FSHookProxy(fspath, pm, remove_mods)
510+
proxy = FSHookProxy(pm, remove_mods)
514511
else:
515512
# all plugins are active for this fspath
516513
proxy = self.config.hook

src/_pytest/outcomes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from typing import Optional
1010
from typing import TypeVar
1111

12-
from packaging.version import Version
13-
1412
TYPE_CHECKING = False # avoid circular import through compat
1513

1614
if TYPE_CHECKING:
@@ -217,6 +215,9 @@ def importorskip(
217215
return mod
218216
verattr = getattr(mod, "__version__", None)
219217
if minversion is not None:
218+
# Imported lazily to improve start-up time.
219+
from packaging.version import Version
220+
220221
if verattr is None or Version(verattr) < Version(minversion):
221222
raise Skipped(
222223
"module %r has __version__ %r, required is: %r"

src/_pytest/terminal.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ def pytest_runtest_logstart(self, nodeid, location):
443443
self.write_ensure_prefix(line, "")
444444
self.flush()
445445
elif self.showfspath:
446-
fsid = nodeid.split("::")[0]
447-
self.write_fspath_result(fsid, "")
446+
self.write_fspath_result(nodeid, "")
448447
self.flush()
449448

450449
def pytest_runtest_logreport(self, report: TestReport) -> None:
@@ -474,10 +473,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
474473
else:
475474
markup = {}
476475
if self.verbosity <= 0:
477-
if not running_xdist and self.showfspath:
478-
self.write_fspath_result(rep.nodeid, letter, **markup)
479-
else:
480-
self._tw.write(letter, **markup)
476+
self._tw.write(letter, **markup)
481477
else:
482478
self._progress_nodeids_reported.add(rep.nodeid)
483479
line = self._locationline(rep.nodeid, *rep.location)

0 commit comments

Comments
 (0)