Skip to content

Conversation

@bearomorphism
Copy link
Collaborator

@bearomorphism bearomorphism commented Dec 13, 2025

Test improvements

  1. Addressed the issues about missing skip_below_py_3_13 and missing forced consistent environment variables to reduce the chance of unnecessary file regression test failures.
  2. Extracted duplicated logics.

@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.84%. Comparing base (2072f8e) to head (ce12748).
⚠️ Report is 1 commits behind head on v4-11-0.

Additional details and impacted files
@@           Coverage Diff            @@
##           v4-11-0    #1726   +/-   ##
========================================
  Coverage    97.84%   97.84%           
========================================
  Files           60       60           
  Lines         2604     2604           
========================================
  Hits          2548     2548           
  Misses          56       56           
Flag Coverage Δ
unittests 97.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Comment on lines -22 to -25
skip_below_py_3_13 = pytest.mark.skipif(
sys.version_info < (3, 13),
reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13",
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The variable name itself does not reflect why we want to set this variable... this may make it hard for future contributors to understand the code correctly

Comment on lines +41 to +46
monkeypatch.setenv("COLUMNS", "80")
monkeypatch.setenv("TERM", "dumb")
monkeypatch.setenv("LC_ALL", "C")
monkeypatch.setenv("LANG", "C")
monkeypatch.setenv("NO_COLOR", "1")
monkeypatch.setenv("PAGER", "cat")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from AI output. I know COLUMNS is necessary, but not sure for the rest

@bearomorphism
Copy link
Collaborator Author

@woile @Lee-W could you review this PR when you have a moment? This PR contains the resolution of error when someone is trying to update CLI --help description. Some other PRs updating CLI options have dependencies on this PR.

Thanks!

@woile
Copy link
Member

woile commented Dec 14, 2025

I don't understand what this is supposed to fix

@bearomorphism
Copy link
Collaborator Author

I don't understand what this is supposed to fix

The behavior of --help of argparse is different in some cases between python 3.13 and below 3.13 as the message of original skip_below_py_3_13 says. Some of --help tests still uses skip_below_py_3_10 before this PR, and those tests still pass in the pipeline luckily.

When we try to add new options to the CLI, the help text changes, and usually we run pytest --regen-all to regenerate the file_regression test file, but the regenerated content may be different depends on the local environment (monkeypatch in this PR addresses this issue).

@bearomorphism
Copy link
Collaborator Author

The following pipeline result is a false alarm test failure caused by forgetting to skip the test below python 3.13.

https://github.com/commitizen-tools/commitizen/actions/runs/20207591917/job/58008470452?pr=1724

Test passes for python version 3.13, 3.14 but not on 3.10

This PR can fix it.

Copy link
Member

@noirbizarre noirbizarre left a comment

Choose a reason for hiding this comment

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

Good to me, but I added some comment for possible later improvements

Comment on lines +10 to +13
@pytest.mark.skipif(
sys.version_info < (3, 13),
reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13",
)
Copy link
Member

Choose a reason for hiding this comment

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

Can't we have different snapshots for Python <3.13 and >=3.13 ?
It seems weird to have some tests skipped for some Python version for things that are existing on those Python versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. I will check how to do it later and will do in another PR.

Comment on lines +40 to +46
# Force consistent terminal output
monkeypatch.setenv("COLUMNS", "80")
monkeypatch.setenv("TERM", "dumb")
monkeypatch.setenv("LC_ALL", "C")
monkeypatch.setenv("LANG", "C")
monkeypatch.setenv("NO_COLOR", "1")
monkeypatch.setenv("PAGER", "cat")
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be a fixture like fixed_term for any test relying on output.
Basically, what it does:

  • COLUMNS fix the width of the term
  • TERM=dumb deactivate reactive output on libs supporting this (like spinners, progress bars...), better for static snapshots.
  • LC_ALL=C and LANG=C disable localization and utf-8 chars in most CLI tools, it ensure test snapshot doesn't fail on non-english setups
  • NO_COLOR is the now "standard" way of disabling ANSI color support (cf. https://no-color.org/)
  • PAGER=cat will avoid user defined pagers like bat to change the output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do in another PR

@noirbizarre noirbizarre mentioned this pull request Dec 28, 2025
1 task
@bearomorphism bearomorphism merged commit c7b8d97 into commitizen-tools:v4-11-0 Dec 28, 2025
18 checks passed
@bearomorphism bearomorphism deleted the test-help branch December 28, 2025 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants