Skip to content

fix: make CLI monitor tests to be able to run on a Windows environment - #1459

Merged
inimaz merged 1 commit into
mlco2:masterfrom
hifarrer:fix/windows-portable-monitor-test
Oct 25, 2026
Merged

inimaz merged 1 commit into
mlco2:masterfrom
hifarrer:fix/windows-portable-monitor-test

Conversation

@hifarrer

@hifarrer hifarrer commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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 x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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.

  • 🟥 AI-vibecoded: You cannot explain the logic. Car analogy : the car drive by itself, you are outside it and just tell it where to go.
  • 🟠 AI-generated: Car analogy : the car drive by itself, you are inside and give instructions.
  • ⭐ AI-assisted. Car analogy : you drive the car, AI help you find your way.
  • ♻️ No AI used. Car analogy : you drive the car.

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@dilipna dilipna left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.05%. Comparing base (24ddb59) to head (5e4ddc4).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inimaz inimaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks @hifarrer! We should run indeed the tests also on a windows machine in the ci

@inimaz
inimaz merged commit d180f2b into mlco2:master Oct 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants