From e7186bef3545a74b141f5cb3197b5cb0dee3163c Mon Sep 17 00:00:00 2001 From: Damien Baty Date: Fri, 12 Apr 2024 17:11:13 +0200 Subject: [PATCH] tests: Type `capfd` instead of documenting by a comment The result is similar: the reader knows where `capfd` comes from, and they can benefit from the typing. --- tests/test_check_branches.py | 4 ++-- tests/test_check_fixmes.py | 4 ++-- tests/test_check_future_tags.py | 4 ++-- tests/test_forget_me_not.py | 4 +++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_check_branches.py b/tests/test_check_branches.py index af7d2e0..9cba48c 100644 --- a/tests/test_check_branches.py +++ b/tests/test_check_branches.py @@ -51,7 +51,7 @@ def test_get_repository_info(): host, owner, repo_name = branches.get_repository_info('.') -def test_output_fresh_branches(capfd): # capfd is a pytest fixture +def test_output_fresh_branches(capfd: pytest.CaptureFixture): config = branches.Config( path=base.TEST_DIR_PATH.parent, max_age=9999, @@ -71,7 +71,7 @@ def test_output_fresh_branches(capfd): # capfd is a pytest fixture assert stdout[0] == "OK: All branches are fresh." -def test_output_old_branches(capfd): # capfd is a pytest fixture +def test_output_old_branches(capfd: pytest.CaptureFixture): with pytest.raises(TypeError): config = branches.Config(host_owner='Polyconseil') # pylint: disable=unexpected-keyword-arg diff --git a/tests/test_check_fixmes.py b/tests/test_check_fixmes.py index 7035382..18118b6 100644 --- a/tests/test_check_fixmes.py +++ b/tests/test_check_fixmes.py @@ -12,7 +12,7 @@ @mock.patch("check_oldies.annotations.get_line_blame", base.fake_get_line_blame) -def test_output_when_all_annotations_are_fresh(capfd): # capfd is a pytest fixture +def test_output_when_all_annotations_are_fresh(capfd: pytest.CaptureFixture): config = annotations.Config( path=base.TEST_DIR_PATH / "data/project1", max_age=9999, @@ -39,7 +39,7 @@ def test_output_when_all_annotations_are_fresh(capfd): # capfd is a pytest fixt assert stdout == expected -def test_output_when_no_annotations(capfd): # capfd is a pytest fixture +def test_output_when_no_annotations(capfd: pytest.CaptureFixture): config = annotations.Config(path=base.TEST_DIR_PATH / "data/project2") with mock.patch("check_oldies.configuration.get_config", return_value=config): diff --git a/tests/test_check_future_tags.py b/tests/test_check_future_tags.py index b04fbb4..049c042 100644 --- a/tests/test_check_future_tags.py +++ b/tests/test_check_future_tags.py @@ -12,7 +12,7 @@ @mock.patch("check_oldies.annotations.get_line_blame", base.fake_get_line_blame) -def test_output_with_orphan_future_tags(capfd): # capfd is a pytest fixture +def test_output_with_orphan_future_tags(capfd: pytest.CaptureFixture): config = annotations.Config( path=base.TEST_DIR_PATH / "data/project3", colorize_errors=False, @@ -35,7 +35,7 @@ def test_output_with_orphan_future_tags(capfd): # capfd is a pytest fixture @mock.patch("check_oldies.annotations.get_line_blame", base.fake_get_line_blame) -def test_output_with_ignored_annotations_orphans_future_tags(capfd): # capfd is a pytest fixture +def test_output_with_ignored_annotations_orphans_future_tags(capfd: pytest.CaptureFixture): config = annotations.Config( path=base.TEST_DIR_PATH / "data/project6", colorize_errors=False, diff --git a/tests/test_forget_me_not.py b/tests/test_forget_me_not.py index 16745bd..d117caa 100644 --- a/tests/test_forget_me_not.py +++ b/tests/test_forget_me_not.py @@ -4,6 +4,8 @@ import os from unittest import mock +import pytest + from check_oldies import forget_me_not from . import base @@ -20,7 +22,7 @@ def in_working_directory(path): @mock.patch("check_oldies.annotations.get_line_blame", base.fake_get_line_blame) -def test_forget_me_not(capfd): # capfd is a pytest fixture +def test_forget_me_not(capfd: pytest.CaptureFixture): with in_working_directory(base.TEST_DIR_PATH / 'data'): forget_me_not.main(argv=[]) captured = capfd.readouterr()