Skip to content

Fix test expectation in test_flags_missing_selector #74

Done

Description

@byMeysaM

While working on the Python test suite, I came across an issue in test_flags_missing_selector in tests/test_generator.py.

pytest_test

Test failure

The test currently expects argparse.ArgumentError when parse_args() is called without providing any arguments:

self.assertRaises(argparse.ArgumentError, parser.parse_args, args=[])

However, DocFilter.add_flags() defines a mutually exclusive argument group with required=True. When none of the required options (--all, --slug, or --first) is provided, argparse raises SystemExit with exit code 2, rather than argparse.ArgumentError.

This means the current test does not match the actual behavior of argparse.

hatch_test

Suggested fix

The test should be updated to expect SystemExit and verify that the exit code is 2:

with self.assertRaises(SystemExit) as context:
    parser.parse_args(args=[])

self.assertEqual(context.exception.code, 2)

The full test suite was also run locally, and all 64 tests passed.

fix-argparse-test-pytest

This change has been implemented in PR #75

Activity

  1. benoit74 commented on Nov 26, 2026

    @benoit74
    Contributor

    QA workflow is only about QA. Tests are run in the tests workflow.

    I don't get the rest of the issue. Do you mean that tests are currently failing on the main branch?

  2. byMeysaM commented on Nov 27, 2026

    @byMeysaM
    Author

    @benoit74

    QA workflow is only about QA. Tests are run in the tests workflow.

    Thank you for pointing this out. I hadn't checked the separate tests workflow, so I was wrong about the tests not being run in CI. Sorry for the confusion.

    I'll update the issue to remove the CI part and keep only the test failure, since the CI concern was based on my misunderstanding of the existing workflows.

    I don't get the rest of the issue. Do you mean that tests are currently failing on the main branch?

    As for the test failure, yes, test_flags_missing_selector fails on the current main branch. The test expects argparse.ArgumentError, but argparse actually raises SystemExit with exit code 2 when the required mutually exclusive arguments are missing.

    I've fixed the expectation in PR #75 and ran the full test suite locally. All 64 tests passed.

  3. changed the title [-]Fix test expectation and consider running Python tests in CI[/-] [+]Fix test expectation in test_flags_missing_selector[/+] on Nov 27, 2026
  4. benoit74 commented on Nov 30, 2026

    @benoit74
    Contributor

    Answered in #75 — this isn't a test bug. The missing-required-group error raises argparse.ArgumentError rather than SystemExit on Python 3.12+, and pyproject.toml requires >=3.12,<3.13; SystemExit: 2 is the 3.11 behaviour. Full suite is 64 passed on main under 3.12.15. Please double-check the Python version your hatch env resolved to.

  5. byMeysaM commented on Dec 2, 2026

    @byMeysaM
    Author

    I've added a more detailed explanation of the Python version discrepancy in #75 (review), including the relevant CPython changes and the project's Python version requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions