Skip to content

test: make colour tests independent of an ambient NO_COLOR (#34) - #48

Merged
4444J99 merged 1 commit into
mainfrom
fix/tests-hermetic-no-color-34
Nov 28, 2026
Merged

4444J99 merged 1 commit into
mainfrom
fix/tests-hermetic-no-color-34

Conversation

@4444J99

@4444J99 4444J99 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #34

Adds rege/tests/conftest.py, which removes an ambient NO_COLOR before the suite imports rege.formatting. Tests only. No library code changes.

Verification receipt

Head verified: cca817cc5e7818c22d9b6ef972f1b1a83223c300. Python 3.13 venv with pip install -e '.[dev]' pytest-xdist (click 8.5.1, pytest 9.2.0).

Command Before (main 7ac2f37) After (this head)
NO_COLOR=1 env -u TERM python -m pytest -q -n 8 2 failed, 2002 passed (test_colors_defined, test_no_color_env_triggers_disable) 2004 passed
NO_COLOR=1 env -u TERM python -m pytest -q (serial) n/a 2004 passed
env -u NO_COLOR -u TERM python -m pytest -q -n 8 2004 passed 2004 passed

No test was skipped, removed or loosened. The NO_COLOR behaviour tests still set NO_COLOR themselves.

Summary by Sourcery

Ensure colour tests produce consistent results regardless of the environment in which the test suite runs.

Enhancements:

  • Make the test suite's colour checks independent of an ambient NO_COLOR environment variable.

Tests:

  • Add shared test-session setup that clears ambient NO_COLOR while preserving explicit coverage of NO_COLOR behaviour.

Summary by CodeRabbit

  • Tests
    • Test runs now begin without an inherited NO_COLOR setting affecting color-related checks.
    • Checks that cover NO_COLOR behavior set it explicitly, making results more consistent across environments and ensuring those scenarios remain tested. This improves the reliability of automated checks without changing the application’s behavior for end users.

@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Tests

Clear an ambient NO_COLOR during test-session setup so colour tests are independent of the caller’s environment.

  • rege/tests/conftest.py L1-13

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T22:46:41.899403Z cca817c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The test setup removes NO_COLOR from the environment when conftest.py is imported. Tests that exercise NO_COLOR set the variable themselves.

Changes: Test setup

Layer / File(s) Summary
Color environment setup
rege/tests/conftest.py
The conftest setup removes NO_COLOR from os.environ and documents why tests that exercise the variable set it themselves.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other

Merge Risk: Minimal · up to cca81

This change only adjusts test setup so an ambient NO_COLOR variable no longer causes spurious color-test failures. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #34 is the only active direct target. Its coding requirement for Colors isolation is implemented. The head diff adds rege/tests/conftest.py, which runs os.environ.pop("NO_COLOR", None) before te… Provide evidence for the following: (1) Results of the two Colors tests run alone and after tests that disable colors, in canonical and permuted order, at head cca817c. (2) A bounded-timeout run of test_repl…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: test colour checks are made independent of an ambient NO_COLOR environment variable. The change adds rege/tests/conftest.py, which removes NO_COLOR before rege.formatt…
Out of Scope Changes check Passed The whole-PR diff against merge base 7ac2f37 changes one file: rege/tests/conftest.py (+13 lines, new file). The change clears NO_COLOR before rege.formatting import, …
Full details: Title check

Explanation

The title names the main change: test colour checks are made independent of an ambient NO_COLOR environment variable. The change adds rege/tests/conftest.py, which removes NO_COLOR before rege.formatting is imported. The title uses the British spelling 'colour' while the code and tests use 'color'. The title also carries an issue reference (#34), which is acceptable.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against merge base 7ac2f37 changes one file: rege/tests/conftest.py (+13 lines, new file). The change clears NO_COLOR before rege.formatting import, which directly serves the Colors-isolation objective of #34. The file has no library code changes. The docstring states that tests exercising NO_COLOR set the variable themselves, and the PR receipt reports no test was skipped, removed, or loosened. No unrelated change is shown in the diff.

Full details: Linked Issues check

Explanation

Issue #34 is the only active direct target. Its coding requirement for Colors isolation is implemented. The head diff adds rege/tests/conftest.py, which runs os.environ.pop("NO_COLOR", None) before test modules import rege.formatting. This matches the issue step 3 request to make module-state isolation deterministic when the defect persists. The PR receipt reports 2004 passed for NO_COLOR=1 with -n 8 and serial runs, against 2 failures on main. Evidence gaps remain. (a) Issue steps 3 and the permutation concern require the two Colors tests to be reproduced individually and after color-disabling tests. The receipt does not show this. The issue states that the failure may come from shared state left by an earlier disabling test. The conftest only clears the environment variable, so it does not address shared Colors attributes set by other tests. (b) Issue step 2 requires the REPL EOF/interrupt test (test_repl_ctrl_c_interrupt) to run with an external bounded timeout. The PR does not report this, and the PR objectives state it is not completed. (c) Issue steps 1 and 4 require a run with the pinned declared dependency versions and recorded JUnit output. The receipt uses click 8.5.1 and pytest 9.2.0 and does not record JUnit, skips, or errors. Steps 2 and 4 are execution and evidence tasks. Their outcome decides whether any further code change is needed, so the coding status cannot be confirmed.

Resolution

Provide evidence for the following: (1) Results of the two Colors tests run alone and after tests that disable colors, in canonical and permuted order, at head cca817c. (2) A bounded-timeout run of test_repl_ctrl_c_interrupt that shows the CLI exits or raises the intended condition. (3) A full-suite run with the declared dependency versions from the snapshot, with JUnit output and resolved package versions recorded. If (1) shows the Colors tests still fail in permuted order, the PR must add deterministic isolation for Colors state. If (2) shows a loop or hang, the REPL EOF/interrupt path requires a code fix in scope for #34.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 11e25d50-e0a5-406d-b2ac-91d10eb83649
Commits

Reviewing files that changed from the base of the PR and between 7ac2f37 and cca817c.

Files selected for processing: 1

  • rege/tests/conftest.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit cca817c

#34 Reproduce census test boundaries under declared dependencies: REPL EOF and Colors isolation · 0 of 5 met · 1 to check by hand

# Requirement Status Notes
1 Reproduce the pinned snapshot in an unprivileged environment with its declared dependencies and record resolved versions. 🟡 Partly met The receipt records Python, pytest and click versions for the PR-base and head runs, but does not establish that it reproduced the issue's pinned snapshot or ran unprivileged.
2 Run the REPL EOF/interrupt test with a bounded timeout and verify its exit behavior. ❌ Not addressed The receipt contains no bounded REPL EOF/interrupt test result.
3 Reproduce the Colors tests individually and after tests that disable colors; make isolation deterministic only if the defect persists. 🟡 Partly met The receipt reproduces failures under ambient NO_COLOR and reports that clearing it resolves them, but does not report individual or test-order reproductions.
4 Run the complete suite, save JUnit, skips, errors and the exact source head, and distinguish environment-only resolution from a repository fix. 🟡 Partly met The receipt reports complete-suite results, the verified head and the environment-only change, but does not report saved JUnit results or skips and errors.
5 Return the execution result to the LAVREA evidence record. 👀 Check by hand (external system) Check whether the receipt and execution result were added to the LAVREA evidence record.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="rege/tests/conftest.py" line_range="13" />
<code_context>
+
+import os
+
+os.environ.pop("NO_COLOR", None)
</code_context>
<issue_to_address>
**Caller loses its colour setting**

When pytest is invoked with `pytest.main()` in a long-lived process whose environment has `NO_COLOR` set, `os.environ.pop` removes the caller’s `NO_COLOR` in the pytest host process, and this conftest has no teardown to restore it, so subsequent application output in that process includes ANSI colours.

Save the original value and restore it in a pytest session teardown hook.
</issue_to_address>

### Comment 2
<location path="rege/tests/conftest.py" line_range="13" />
<code_context>
+
+import os
+
+os.environ.pop("NO_COLOR", None)
</code_context>
<issue_to_address>
**Change lacks narrative counterpart**

When this PR adds test-suite setup without a `docs/logos/` update, the added test-session environment change has no corresponding entry in `docs/logos/`, so the required narrative record omits this change.

Add a corresponding update to the narrative record in `docs/logos/`.
</issue_to_address>

### Comment 3
<location path="rege/tests/conftest.py" line_range="13" />
<code_context>
+
+import os
+
+os.environ.pop("NO_COLOR", None)
</code_context>
<issue_to_address>
**Verify module-state isolation**

The issue asks to reproduce the Colors tests individually and after tests that disable colors before attributing the failures. This setup clears ambient NO_COLOR, but the receipt does not establish whether order-dependent module-state failures persist.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: rege/tests/conftest.py:13, rege/tests/conftest.py:13


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread rege/tests/conftest.py

import os

os.environ.pop("NO_COLOR", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Caller loses its colour setting

When pytest is invoked with pytest.main() in a long-lived process whose environment has NO_COLOR set, os.environ.pop removes the caller’s NO_COLOR in the pytest host process, and this conftest has no teardown to restore it, so subsequent application output in that process includes ANSI colours.

Save the original value and restore it in a pytest session teardown hook.

Prompt for AI agents
In `rege/tests/conftest.py` at line 13:

**Caller loses its colour setting**

When pytest is invoked with `pytest.main()` in a long-lived process whose environment has `NO_COLOR` set, `os.environ.pop` removes the caller’s `NO_COLOR` in the pytest host process, and this conftest has no teardown to restore it, so subsequent application output in that process includes ANSI colours.

Save the original value and restore it in a pytest session teardown hook.

Comment thread rege/tests/conftest.py

import os

os.environ.pop("NO_COLOR", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ Low · Change lacks narrative counterpart

When this PR adds test-suite setup without a docs/logos/ update, the added test-session environment change has no corresponding entry in docs/logos/, so the required narrative record omits this change.

Add a corresponding update to the narrative record in docs/logos/.

Prompt for AI agents
In `rege/tests/conftest.py` at line 13:

**Change lacks narrative counterpart**

When this PR adds test-suite setup without a `docs/logos/` update, the added test-session environment change has no corresponding entry in `docs/logos/`, so the required narrative record omits this change.

Add a corresponding update to the narrative record in `docs/logos/`.

From GEMINI.md L181:

Nature demands a documentation counterpart. This formation maintains its narrative record in `docs/logos/`.

Comment thread rege/tests/conftest.py

import os

os.environ.pop("NO_COLOR", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Verify module-state isolation

The issue asks to reproduce the Colors tests individually and after tests that disable colors before attributing the failures. This setup clears ambient NO_COLOR, but the receipt does not establish whether order-dependent module-state failures persist.

Prompt for AI agents
In `rege/tests/conftest.py` at line 13:

**Verify module-state isolation**

The issue asks to reproduce the Colors tests individually and after tests that disable colors before attributing the failures. This setup clears ambient NO_COLOR, but the receipt does not establish whether order-dependent module-state failures persist.

From #34:

Reproduce the Colors tests individually and after tests that disable colors; make isolation deterministic only if the defect persists.

@4444J99
4444J99 merged commit 1ec27f8 into main Nov 28, 2026
10 checks passed
@4444J99
4444J99 deleted the fix/tests-hermetic-no-color-34 branch November 28, 2026 22:47
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reproduce census test boundaries under declared dependencies: REPL EOF and Colors isolation

1 participant