From d1d3fa6060fe1e040abac20feb33f526708bd05a Mon Sep 17 00:00:00 2001 From: Nikos Kallergis Date: Wed, 30 Oct 2024 19:03:59 +0200 Subject: [PATCH 1/2] Adds a pdb flag under the`unittest task --- changes/194.added | 1 + tasks.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changes/194.added diff --git a/changes/194.added b/changes/194.added new file mode 100644 index 0000000..16cf076 --- /dev/null +++ b/changes/194.added @@ -0,0 +1 @@ +Added a `pdb` flag under the `unittest` task. \ No newline at end of file diff --git a/tasks.py b/tasks.py index c4b4b24..8c5e3db 100644 --- a/tasks.py +++ b/tasks.py @@ -815,6 +815,7 @@ def unittest( # noqa: PLR0913 label="nautobot_dev_example", failfast=False, buffer=True, + pdb=False, pattern="", verbose=False, ): @@ -827,6 +828,8 @@ def unittest( # noqa: PLR0913 command += " --failfast" if buffer: command += " --buffer" + if pdb: + command += " --pdb" if pattern: command += f" -k='{pattern}'" if verbose: @@ -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): """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): @@ -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!") From 314040b6fba2b121747a093fe1f49f48f5dacdb6 Mon Sep 17 00:00:00 2001 From: Nikos Kallergis Date: Thu, 31 Oct 2024 09:46:36 +0200 Subject: [PATCH 2/2] Adds entries to the help decorators, fixes wording for the changelog fragment --- changes/194.added | 2 +- tasks.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changes/194.added b/changes/194.added index 16cf076..f2c2b39 100644 --- a/changes/194.added +++ b/changes/194.added @@ -1 +1 @@ -Added a `pdb` flag under the `unittest` task. \ No newline at end of file +Added a `pdb` flag to the `invoke unittest` task. \ No newline at end of file diff --git a/tasks.py b/tasks.py index 8c5e3db..0e8bb1a 100644 --- a/tasks.py +++ b/tasks.py @@ -805,6 +805,7 @@ def check_migrations(context): "label": "specify a directory or module to test instead of running all Nautobot tests", "failfast": "fail as soon as a single test fails don't run the entire test suite", "buffer": "Discard output from passing tests", + "pdb": "Start the Python debugger shell on test failures to allow for interactive debugging", "pattern": "Run specific test methods, classes, or modules instead of all tests", "verbose": "Enable verbose test output.", } @@ -851,6 +852,8 @@ def unittest_coverage(context): "failfast": "fail as soon as a single test fails don't run the entire test suite. (default: False)", "keepdb": "Save and re-use test database between test runs for faster re-testing. (default: False)", "lint-only": "Only run linters; unit tests will be excluded. (default: False)", + "buffer": "Discard output from passing tests", + "pdb": "Start the Python debugger shell on test failures to allow for interactive debugging", } ) def tests(context, failfast=False, keepdb=False, lint_only=False, buffer=True, pdb=False):