From a47ec2bd2b35f8489aa804ec9ddcfe357cc9b737 Mon Sep 17 00:00:00 2001 From: Terry Kong Date: Wed, 26 Mar 2025 09:25:25 -0700 Subject: [PATCH] fix: unit test error when coverage wasn't specified Behavior now is to tell the user to set it in the unit_results.json Signed-off-by: Terry Kong --- tests/unit/conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index b13d6588a4..1dbbd6a169 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -51,7 +51,7 @@ class UnitTestData(TypedDict): start_time: str metrics: dict gpu_types: list[str] - coverage: dict + coverage: str def pytest_sessionstart(session): @@ -83,7 +83,7 @@ def pytest_sessionstart(session): start_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), metrics={}, gpu_types=[], - coverage={}, + coverage="[n/a] run with --cov=nemo_reinforcer", ) @@ -122,10 +122,16 @@ def session_data(request, init_ray_cluster): ############################################################ # We directly access the coverage controller from the plugin manager # so we can access the coverage total before the pytest session finishes. + cov_controller = None if request.config.pluginmanager.hasplugin("_cov"): plugin = request.config.pluginmanager.getplugin("_cov") if plugin.cov_controller: cov_controller = plugin.cov_controller + + if not cov_controller: + # Means the user didn't run with --cov=... + return + # We currently don't use the cov_report since we can always access the coverage.json later, but # in the future if we want to report the coverage more granularly as part of the session finish, # we can access it here.