Skip to content

Commit

Permalink
Extract no-deprecation-warning asserter as a context manager
Browse files Browse the repository at this point in the history
+ Remove the TODO suggesting the diff not be computed from a real
  commit, since we're going to have the logic for that in use in
  forthcoming commit-specific deprecation warning tests anyway.
  • Loading branch information
EliahKagan committed Mar 28, 2024
1 parent e3728c3 commit ff4b58d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/deprecation/test_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Tests of assorted deprecation warnings with no extra subtleties to check."""

import contextlib
import gc
import warnings

Expand All @@ -12,6 +13,15 @@
from git.repo import Repo


@contextlib.contextmanager
def _assert_no_deprecation_warning():
"""Context manager to assert that code does not issue any deprecation warnings."""
with warnings.catch_warnings():
# FIXME: Refine this to filter for deprecation warnings from GitPython.
warnings.simplefilter("error", DeprecationWarning)
yield


@pytest.fixture
def commit(tmp_path):
"""Fixture to supply a one-commit repo's commit, enough for deprecation tests."""
Expand All @@ -26,7 +36,6 @@ def commit(tmp_path):
@pytest.fixture
def diff(commit):
"""Fixture to supply a single-file diff."""
# TODO: Consider making a fake diff rather than using a real repo and commit.
(diff,) = commit.diff(NULL_TREE) # Exactly one file in the diff.
yield diff

Expand All @@ -39,7 +48,5 @@ def test_diff_renamed_warns(diff):

def test_diff_renamed_file_does_not_warn(diff):
"""The preferred Diff.renamed_file property issues no deprecation warning."""
with warnings.catch_warnings():
# FIXME: Refine this to filter for deprecation warnings from GitPython.
warnings.simplefilter("error", DeprecationWarning)
with _assert_no_deprecation_warning():
diff.renamed_file

0 comments on commit ff4b58d

Please sign in to comment.