From a36a644e045946b4f6e35f79f405fafa0818575f Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 18 Dec 2024 16:20:46 +0800 Subject: [PATCH] display current test function name --- pymatviz/utils/testing.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pymatviz/utils/testing.py b/pymatviz/utils/testing.py index a147249d..9c081679 100644 --- a/pymatviz/utils/testing.py +++ b/pymatviz/utils/testing.py @@ -22,6 +22,13 @@ def interactive_check( ) -> bool | None: """Ask a human to visually inspect a plot. + Note: `pytest` would capture output by default, and you would + need to pass `-s` to release capture. + + Todo: + - scale figure size by display. + - possible to automatically release `pytest` capture? + Args: plot (plt.Figure | plt.Axes): Plot to inspect. elem_to_check (str): Prompt for what element in the plot to check. @@ -57,11 +64,16 @@ def interactive_check( # Ask the user to check (treat KeyboardInterrupt as "yes") try: - good_enough: bool = ( - input(f"Please check the {elem_to_check}. Is it looking good? (y/n): ") - .strip() - .lower() - ) == "y" + current_test_name = os.environ.get("PYTEST_CURRENT_TEST", "").removesuffix( + "(call)" + ) + print( # noqa: T201 (print) + f"\nCurrently checking: {current_test_name}" + f"\nPlease check the '{elem_to_check}'. ", + end="", + ) + + good_enough: bool = input("Is it looking good? (y/n): ").strip().lower() == "y" except KeyboardInterrupt: good_enough = True