Repository navigation
fix: make CLI monitor tests to be able to run on a Windows environment - #1459
Conversation
dilipna
left a comment
There was a problem hiding this comment.
Tested on Windows 11 with Python 3.12 (the PR description used 3.13), on master 24ddb59a: without this change tests/cli has the same 2 failures (exit code 127, Command not found: echo); with it, 78 passed. sys.executable keeps both tests running a real child process through run_and_monitor, so nothing is lost on Linux. Looks good to me.
The rest of the suite has 13 more failures on Windows that this PR doesn't touch (one of them also fails on any machine with an NVIDIA GPU); I wrote them up in #1460.
(Checked with an AI assistant, Claude Code.)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1459 +/- ##
=======================================
Coverage 93.05% 93.05%
=======================================
Files 50 50
Lines 5527 5527
=======================================
Hits 5143 5143
Misses 384 384 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Two tests in tests/cli/test_cli_main.py (test_monitor_run_and_monitor and test_monitor_accepts_tracker_options) ran a real echo through codecarbon monitor.
I replaced it with the Python interpreter (sys.executable), and added import sys.
Related Issue
None. I found it by running the tests on Windows.
Motivation and Context
echo is a cmd.exe built-in on Windows, not an executable. run_and_monitor calls subprocess.Popen without a shell, so it raises FileNotFoundError and the command exits 127.
Both tests failed on Windows when you ran them in PowerShell.
The interpreter exists on every OS, so the tests still run the same code path and keep the coverage on all platforms.
How Has This Been Tested?
Windows 11 and Python 3.13, using PowerShell. Check your exact version with uv run python --version.
Command: $env:CODECARBON_ALLOW_MULTIPLE_RUNS = "True"; uv run pytest tests/cli -q
Before: 2 failed, 76 passed (exit code 127). After: 78 passed.
The project’s pre-commit hooks pass on the changed file (autoflake, isort, black, flake8).
Not run: the full test suite, and Linux or macOS. Say that Linux CI is the check for the other platforms.
Screenshots (if appropriate):N/A
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:AI Usage Disclosure
Please refer to docs/how-to/ai-policy.md for detailed guidelines on how to disclose AI usage in your PR. Accurately completing this section is mandatory.
Checklist:
Go over all the following points, and put an
xin all the boxes that apply.