Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a pdb flag under the unittest task #55

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/194.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a `pdb` flag under the `unittest` task.
nkallergis marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ def unittest( # noqa: PLR0913
label="nautobot_dev_example",
failfast=False,
buffer=True,
pdb=False,
pattern="",
verbose=False,
):
Expand All @@ -827,6 +828,8 @@ def unittest( # noqa: PLR0913
command += " --failfast"
if buffer:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps?

Suggested change
if buffer:
if buffer and not pdb:

Copy link
Author

Choose a reason for hiding this comment

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

I toyed with this idea but I feel it's a bit counterintuitive and against the "explicit better than implicit" principle. Just a personal opinion though, I'm OK to implement it this way if you feel strong about it...

Copy link
Contributor

Choose a reason for hiding this comment

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

Whenever I put a breakpoint in a test and forget to use --no-buffer it doesn't output anything and just freezes until I do a docker stop on the container. Does the same thing happen with --pdb?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, you have to add --no-buffer too to get to the interesting part. I take it you prefer to auto-add it as it makes more sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the behavior when you forget --no-buffer is that it silently fails then I would prefer to add it automatically

command += " --buffer"
if pdb:
command += " --pdb"
if pattern:
command += f" -k='{pattern}'"
if verbose:
Expand All @@ -850,7 +853,7 @@ def unittest_coverage(context):
"lint-only": "Only run linters; unit tests will be excluded. (default: False)",
}
)
def tests(context, failfast=False, keepdb=False, lint_only=False):
def tests(context, failfast=False, keepdb=False, lint_only=False, buffer=True, pdb=False):
nkallergis marked this conversation as resolved.
Show resolved Hide resolved
"""Run all tests for this app."""
# If we are not running locally, start the docker containers so we don't have to for each test
if not is_truthy(context.nautobot_dev_example.local):
Expand All @@ -873,7 +876,7 @@ def tests(context, failfast=False, keepdb=False, lint_only=False):
validate_app_config(context)
if not lint_only:
print("Running unit tests...")
unittest(context, failfast=failfast, keepdb=keepdb)
unittest(context, failfast=failfast, keepdb=keepdb, buffer=buffer, pdb=pdb)
unittest_coverage(context)
print("All tests have passed!")

Expand Down