summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-03-21 13:47:41 +0100
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-03-29 17:04:12 +0200
commit8387e01902961ab4af366bd442511d11a6909c3e (patch)
treec81d4094f8b2f9eb7ed7faeda8cc2548d9a0c6bb /testing
parentf0128253816d5d1783c6c1def4cc8957a34d3436 (diff)
downloadsetuptools-scm-8387e01902961ab4af366bd442511d11a6909c3e.tar.gz
breaking: replace trace with logging
Diffstat (limited to 'testing')
-rw-r--r--testing/conftest.py35
-rw-r--r--testing/test_regressions.py23
2 files changed, 24 insertions, 34 deletions
diff --git a/testing/conftest.py b/testing/conftest.py
index e1c8160..58a2589 100644
--- a/testing/conftest.py
+++ b/testing/conftest.py
@@ -1,8 +1,11 @@
from __future__ import annotations
+import contextlib
import os
from pathlib import Path
+from types import TracebackType
from typing import Any
+from typing import Iterator
import pytest
@@ -40,25 +43,35 @@ def pytest_addoption(parser: Any) -> None:
)
-class DebugMode:
- def __init__(self, monkeypatch: pytest.MonkeyPatch):
- self.__monkeypatch = monkeypatch
- self.__module = setuptools_scm._trace
+class DebugMode(contextlib.AbstractContextManager): # type: ignore[type-arg]
+ __module = setuptools_scm._log
- __monkeypatch: pytest.MonkeyPatch
+ def __init__(self) -> None:
+ self.__stack = contextlib.ExitStack()
+
+ def __enter__(self) -> DebugMode:
+ self.enable()
+ return self
+
+ def __exit__(
+ self,
+ exc_type: type[BaseException] | None,
+ exc_val: BaseException | None,
+ exc_tb: TracebackType | None,
+ ) -> None:
+ self.disable()
def enable(self) -> None:
- self.__monkeypatch.setattr(self.__module, "DEBUG", True)
+ self.__stack.enter_context(self.__module.defer_to_pytest())
def disable(self) -> None:
- self.__monkeypatch.setattr(self.__module, "DEBUG", False)
+ self.__stack.close()
@pytest.fixture(autouse=True)
-def debug_mode(monkeypatch: pytest.MonkeyPatch) -> DebugMode:
- debug_mode = DebugMode(monkeypatch)
- debug_mode.enable()
- return debug_mode
+def debug_mode() -> Iterator[DebugMode]:
+ with DebugMode() as debug_mode:
+ yield debug_mode
@pytest.fixture
diff --git a/testing/test_regressions.py b/testing/test_regressions.py
index f7b4b17..4c27ca9 100644
--- a/testing/test_regressions.py
+++ b/testing/test_regressions.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import os
import pprint
import subprocess
import sys
@@ -16,7 +15,6 @@ from pathlib import Path
import pytest
from setuptools_scm import Configuration
-from setuptools_scm import get_version
from setuptools_scm.git import parse
from setuptools_scm._run_cmd import run
@@ -51,27 +49,6 @@ def test_pkginfo_noscmroot(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> N
assert res.stdout == "0.1.dev0"
-def test_pip_egg_info(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
- """if we are indeed a sdist, the root does not apply"""
-
- # we should get the version from pkg-info if git is broken
- p = tmp_path.joinpath("sub/package")
- p.mkdir(parents=True)
- tmp_path.joinpath(".git").mkdir()
- p.joinpath("setup.py").write_text(
- "from setuptools import setup;" 'setup(use_scm_version={"root": ".."})'
- )
-
- with pytest.raises(LookupError):
- get_version(root=os.fspath(p), fallback_root=os.fspath(p))
-
- bad_egg_info = p.joinpath("pip-egg-info/random.egg-info/")
- bad_egg_info.mkdir(parents=True)
-
- bad_egg_info.joinpath("PKG-INFO").write_text("Version: 1.0")
- assert get_version(root=os.fspath(p), fallback_root=os.fspath(p)) == "1.0"
-
-
@pytest.mark.issue(164)
def test_pip_download(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(tmp_path)