Merge pull request #7238 from bluetech/micro-optimizations-1
A few tiny micro-optimizations/simplifications
This commit is contained in:
commit
b38edec60f
|
@ -23,7 +23,6 @@ from typing import Union
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
import py
|
import py
|
||||||
from packaging.version import Version
|
|
||||||
from pluggy import HookimplMarker
|
from pluggy import HookimplMarker
|
||||||
from pluggy import HookspecMarker
|
from pluggy import HookspecMarker
|
||||||
from pluggy import PluginManager
|
from pluggy import PluginManager
|
||||||
|
@ -1059,6 +1058,9 @@ class Config:
|
||||||
|
|
||||||
minver = self.inicfg.get("minversion", None)
|
minver = self.inicfg.get("minversion", None)
|
||||||
if minver:
|
if minver:
|
||||||
|
# Imported lazily to improve start-up time.
|
||||||
|
from packaging.version import Version
|
||||||
|
|
||||||
if Version(minver) > Version(pytest.__version__):
|
if Version(minver) > Version(pytest.__version__):
|
||||||
raise pytest.UsageError(
|
raise pytest.UsageError(
|
||||||
"%s:%d: requires pytest-%s, actual pytest-%s'"
|
"%s:%d: requires pytest-%s, actual pytest-%s'"
|
||||||
|
|
|
@ -456,10 +456,7 @@ def _check_initialpaths_for_relpath(session, fspath):
|
||||||
|
|
||||||
|
|
||||||
class FSHookProxy:
|
class FSHookProxy:
|
||||||
def __init__(
|
def __init__(self, pm: PytestPluginManager, remove_mods) -> None:
|
||||||
self, fspath: py.path.local, pm: PytestPluginManager, remove_mods
|
|
||||||
) -> None:
|
|
||||||
self.fspath = fspath
|
|
||||||
self.pm = pm
|
self.pm = pm
|
||||||
self.remove_mods = remove_mods
|
self.remove_mods = remove_mods
|
||||||
|
|
||||||
|
@ -510,7 +507,7 @@ class FSCollector(Collector):
|
||||||
remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
|
remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
|
||||||
if remove_mods:
|
if remove_mods:
|
||||||
# one or more conftests are not in use at this fspath
|
# one or more conftests are not in use at this fspath
|
||||||
proxy = FSHookProxy(fspath, pm, remove_mods)
|
proxy = FSHookProxy(pm, remove_mods)
|
||||||
else:
|
else:
|
||||||
# all plugins are active for this fspath
|
# all plugins are active for this fspath
|
||||||
proxy = self.config.hook
|
proxy = self.config.hook
|
||||||
|
|
|
@ -9,8 +9,6 @@ from typing import cast
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
|
||||||
from packaging.version import Version
|
|
||||||
|
|
||||||
TYPE_CHECKING = False # avoid circular import through compat
|
TYPE_CHECKING = False # avoid circular import through compat
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -217,6 +215,9 @@ def importorskip(
|
||||||
return mod
|
return mod
|
||||||
verattr = getattr(mod, "__version__", None)
|
verattr = getattr(mod, "__version__", None)
|
||||||
if minversion is not None:
|
if minversion is not None:
|
||||||
|
# Imported lazily to improve start-up time.
|
||||||
|
from packaging.version import Version
|
||||||
|
|
||||||
if verattr is None or Version(verattr) < Version(minversion):
|
if verattr is None or Version(verattr) < Version(minversion):
|
||||||
raise Skipped(
|
raise Skipped(
|
||||||
"module %r has __version__ %r, required is: %r"
|
"module %r has __version__ %r, required is: %r"
|
||||||
|
|
|
@ -443,8 +443,7 @@ class TerminalReporter:
|
||||||
self.write_ensure_prefix(line, "")
|
self.write_ensure_prefix(line, "")
|
||||||
self.flush()
|
self.flush()
|
||||||
elif self.showfspath:
|
elif self.showfspath:
|
||||||
fsid = nodeid.split("::")[0]
|
self.write_fspath_result(nodeid, "")
|
||||||
self.write_fspath_result(fsid, "")
|
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def pytest_runtest_logreport(self, report: TestReport) -> None:
|
def pytest_runtest_logreport(self, report: TestReport) -> None:
|
||||||
|
@ -474,9 +473,6 @@ class TerminalReporter:
|
||||||
else:
|
else:
|
||||||
markup = {}
|
markup = {}
|
||||||
if self.verbosity <= 0:
|
if self.verbosity <= 0:
|
||||||
if not running_xdist and self.showfspath:
|
|
||||||
self.write_fspath_result(rep.nodeid, letter, **markup)
|
|
||||||
else:
|
|
||||||
self._tw.write(letter, **markup)
|
self._tw.write(letter, **markup)
|
||||||
else:
|
else:
|
||||||
self._progress_nodeids_reported.add(rep.nodeid)
|
self._progress_nodeids_reported.add(rep.nodeid)
|
||||||
|
|
Loading…
Reference in New Issue