diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75941dcd9..1574651c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,6 +54,8 @@ repos: - id: mypy files: ^(src/|testing/) args: [] + additional_dependencies: + - iniconfig>=1.1.0 - repo: local hooks: - id: rst diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index 04fa8f375..2edf54536 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -27,7 +27,7 @@ def _parse_ini_config(path: Path) -> iniconfig.IniConfig: Raise UsageError if the file cannot be parsed. """ try: - return iniconfig.IniConfig(path) + return iniconfig.IniConfig(str(path)) except iniconfig.ParseError as exc: raise UsageError(str(exc)) from exc diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index e3094a9df..a4142037d 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -32,6 +32,7 @@ from weakref import WeakKeyDictionary import attr import py from iniconfig import IniConfig +from iniconfig import SectionWrapper import pytest from _pytest import timing @@ -785,10 +786,10 @@ class Pytester: """Write a tox.ini file with 'source' as contents.""" return self.makefile(".ini", tox=source) - def getinicfg(self, source: str) -> IniConfig: + def getinicfg(self, source: str) -> SectionWrapper: """Return the pytest section from the tox.ini config file.""" p = self.makeini(source) - return IniConfig(p)["pytest"] + return IniConfig(str(p))["pytest"] def makepyprojecttoml(self, source: str) -> Path: """Write a pyproject.toml file with 'source' as contents. @@ -1541,9 +1542,9 @@ class Testdir: """See :meth:`Pytester.makeini`.""" return py.path.local(str(self._pytester.makeini(source))) - def getinicfg(self, source) -> py.path.local: + def getinicfg(self, source: str) -> SectionWrapper: """See :meth:`Pytester.getinicfg`.""" - return py.path.local(str(self._pytester.getinicfg(source))) + return self._pytester.getinicfg(source) def makepyprojecttoml(self, source) -> py.path.local: """See :meth:`Pytester.makepyprojecttoml`."""