Skip to content

Commit

Permalink
Failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Jul 24, 2024
1 parent 4e7ad45 commit 7b5bf1a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/unit/contrib/django/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

import argparse

from procrastinate.contrib.django.management.commands import (
procrastinate as procrastinate_command,
)


def test_procrastinate_command():
# This test might be brittle as it uses internal argparse attributes
# It's linked to https://github.com/procrastinate-org/procrastinate/pull/1095
parser = procrastinate_command.Command().create_parser("manage.py", "procrastinate")

error = """
If this test fails, it means that an argument named "args" has been added
(or renamed) in the procrastinate CLI, and is exposed in the Django procrastinate
management command. This is problematic because "args" is a special name that
Django removes from the command line arguments before passing them to the
management command. To fix this error, use a different name for the argument.
See:
- https://github.com/django/django/blob/f9bf616597d56deac66d9d6bb753b028dd9634cc/django/core/management/base.py#L410
- https://github.com/procrastinate-org/procrastinate/pull/1095
"""

def assert_no_action_named_args(parser):
for action in parser._actions:
assert getattr(action, "dest", "") != (
"args"
), f"'args' found in {parser.prog}\n{error}"
if isinstance(action, argparse._SubParsersAction):
for subparser in action.choices.values():
assert_no_action_named_args(subparser)

assert_no_action_named_args(parser)

0 comments on commit 7b5bf1a

Please sign in to comment.