Repository: nautobot/nautobot (Python)

Issue:
Make unittest `--cache-test-fixtures` and `--keepdb` arguments default-true
<!--
    NOTE: This template is for use by maintainers only. Please do not submit
    an issue using this template unless you have been specifically asked to
    do so.
-->
### Proposed Changes

Change the `invoke unittest` arguments `--cache-test-fixtures` and `--keepdb` to be enabled by default and opt-out, instead of their current opt-in behavior. #5858 might be a prerequisite.

Maybe also make it so that if not specifying a particular `--label`, we should default-enable the `--parallel` flag since running the full test suite is so time consuming otherwise?

<!-- Provide justification for the proposed change(s). -->
### Justification

Provide well-performing default behavior for the task, reducing the amount of "team knowledge" required for new developers to have a good development experience.



Fix (patch):
diff --git a/.github/workflows/ci_integration.yml b/.github/workflows/ci_integration.yml
index c8516e5ae56..9aef21ad2ca 100644
--- a/.github/workflows/ci_integration.yml
+++ b/.github/workflows/ci_integration.yml
@@ -72,7 +72,7 @@ jobs:
           poetry-version: "1.8.2"
           python-version: "3.12"
       - name: "Run unittest"
-        run: "poetry run invoke unittest --failfast --keepdb --parallel"
+        run: "poetry run invoke unittest --failfast --no-keepdb --no-cache-test-fixtures --parallel"
   tests-mysql:
     name: "Unit tests (MySQL and Python 3.8)"
     runs-on: "ubuntu-22.04"
@@ -108,7 +108,7 @@ jobs:
           poetry-version: "1.8.2"
           python-version: "3.8"
       - name: "Run unittest"
-        run: "poetry run invoke unittest --failfast --keepdb --parallel"
+        run: "poetry run invoke unittest --failfast --no-keepdb --no-cache-test-fixtures --parallel"
   migration-tests-mysql:
     name: "Run migrations against test dataset (MySQL and Python 3.8)"
     runs-on: "ubuntu-20.04"
diff --git a/.github/workflows/ci_pullrequest.yml b/.github/workflows/ci_pullrequest.yml
index dcddc69c248..a00c91eef9a 100644
--- a/.github/workflows/ci_pullrequest.yml
+++ b/.github/workflows/ci_pullrequest.yml
@@ -184,7 +184,7 @@ jobs:
           poetry-version: "1.8.2"
           python-version: "3.8"
       - name: "Run unittest"
-        run: "poetry run invoke unittest --failfast --keepdb --parallel"
+        run: "poetry run invoke unittest --failfast --no-keepdb --no-cache-test-fixtures --parallel"
     needs:
       - "check-migrations"
       - "check-schema"
@@ -227,7 +227,7 @@ jobs:
           poetry-version: "1.8.2"
           python-version: "3.12"
       - name: "Run unittest"
-        run: "poetry run invoke unittest --failfast --keepdb --parallel"
+        run: "poetry run invoke unittest --failfast --no-keepdb --no-cache-test-fixtures --parallel"
     needs:
       - "check-migrations"
       - "check-schema"
diff --git a/changes/5859.housekeeping b/changes/5859.housekeeping
new file mode 100644
index 00000000000..e13e438bc82
--- /dev/null
+++ b/changes/5859.housekeeping
@@ -0,0 +1,2 @@
+Changed `--cache-test-fixtures` and `--keepdb` flags from opt-in to opt-out for `invoke unittest` and `invoke integration-test` commands.
+Changed `invoke unittest` to automatically include `--parallel` flag when running the entire unit test suite.
diff --git a/nautobot/docs/development/core/getting-started.md b/nautobot/docs/development/core/getting-started.md
index 4992a96127a..6733f42fa2d 100644
--- a/nautobot/docs/development/core/getting-started.md
+++ b/nautobot/docs/development/core/getting-started.md
@@ -636,12 +636,12 @@ Unit tests are run using the `invoke unittest` command (if using the Docker deve
 
 The `invoke unittest` command supports a number of optional parameters to influence its behavior. Careful use of these parameters can greatly reduce the time it takes to run and re-run tests during development.
 
-* `--cache-test-fixtures` - Cache [test factory data](./testing.md#factory-caching) to disk, or if a cache is already present, load from that cache when initializing the test environment. Can significantly improve the initial startup time of the test suite after your first test run.
 * `--failfast` - Fail as soon as any test failure or error condition is encountered, instead of running to completion.
-* `--keepdb` - Save and reuse the initialized test database between test runs. Can significantly improve the initial startup time of the test suite after your first test run. **Do not use if you're actively making changes to model definitions or migrations.**
 * `--label <module.path>` - Only run the specific subset of tests. Can be broad (`--label nautobot.core.tests`) or specific (`--label nautobot.core.tests.test_graphql.GraphQLQueryTestCase`).
 * `--no-buffer` - Allow stdout/stderr output from the test to be seen in your terminal, instead of being hidden. **If you're debugging code with `breakpoint()`, you should use this option, as otherwise you'll never see the breakpoint happen.**
-* `--parallel` - Split the tests across multiple parallel subprocesses. Can greatly reduce the runtime of the entire test suite when used. Auto-detects the number of workers if not specified with `--parallel-workers`.
+* `--no-cache-test-fixtures` - Prevent caching [test factory data](./testing.md#factory-caching) to disk, or if a cache is already present, prevent loading from that cache when initializing the test environment.
+* `--no-keepdb` - Prevent saving and reusing the initialized test database between test runs. **The `--no-keepdb` option is mandatory if you're actively making changes to model definitions or migrations.**
+* `--parallel` - Split the tests across multiple parallel subprocesses. Can greatly reduce the runtime of the entire test suite when used. Auto-detects the number of workers if not specified with `--parallel-workers`. This parameter is automatically included if no `--label` is specified.
 * `--parallel-workers` - Specify the number of workers to use when running tests in parallel. Implies `--parallel`.
 * `--pattern` - Only run tests which match the given substring. Can be used multiple times.
 * `--skip-docs-build` - Skip building/rebuilding the static Nautobot documentation before running the test. Saves some time on reruns when you haven't changed the documentation source files.
@@ -652,33 +652,39 @@ The `invoke unittest` command supports a number of optional parameters to influe
 In general, when you first run the Nautobot tests in your local copy of the repository, we'd recommend:
 
 ```no-highlight
-invoke unittest --cache-test-fixtures --keepdb --parallel
+invoke unittest
 ```
 
 When there are too many cores on the testing machine, you can limit the number of parallel workers:
 
 ```no-highlight
-invoke unittest --cache-test-fixtures --keepdb --parallel-workers 4
+invoke unittest --parallel-workers 4
 ```
 
 On subsequent reruns, you can add the other performance-related options:
 
 ```no-highlight
-invoke unittest --cache-test-fixtures --keepdb --parallel --skip-docs-build
-invoke unittest --cache-test-fixtures --keepdb --parallel --skip-docs-build --label nautobot.core.tests
+invoke unittest --skip-docs-build
+invoke unittest --skip-docs-build --label nautobot.core.tests
 ```
 
-When switching between significantly different branches of the code base (e.g. `main` vs `develop` vs `next`), you'll need to for once omit the `--keepdb` option so that the test database can be destroyed and recreated appropriately:
+When switching between significantly different branches of the code base (e.g. `main` vs `develop` vs `next`), you'll need to for once include the `--no-keepdb` option so that the test database can be destroyed and recreated appropriately:
 
 ```no-highlight
-invoke unittest --cache-test-fixtures --parallel
+invoke unittest --no-keepdb
+```
+
+To not use the cached test fixture, you will need to include the `--no-cache-test-fixtures` flag
+
+```no-highlight
+invoke unittest --no-cache-test-fixtures
 ```
 
 To limit the test to a specific pattern or label, you can use the `--label` and `--pattern` options:
 
 ```no-highlight
-invoke unittest --cache-test-fixtures --keepdb --verbose --skip-docs-build --label nautobot.core.tests.dcim.test_views.DeviceTestCase
-invoke unittest --cache-test-fixtures --keepdb --verbose --skip-docs-build --pattern Controller
+invoke unittest --verbose --skip-docs-build --label nautobot.core.tests.dcim.test_views.DeviceTestCase
+invoke unittest --verbose --skip-docs-build --pattern Controller
 ```
 
 #### Integration Tests
diff --git a/tasks.py b/tasks.py
index 1db945afd6a..e7640d2cf96 100644
--- a/tasks.py
+++ b/tasks.py
@@ -707,8 +707,8 @@ def check_schema(context, api_version=None):
 )
 def unittest(
     context,
-    cache_test_fixtures=False,
-    keepdb=False,
+    cache_test_fixtures=True,
+    keepdb=True,
     label="nautobot",
     pattern=None,
     failfast=False,
@@ -750,7 +750,7 @@ def unittest(
         command += " --buffer"
     if verbose:
         command += " --verbosity 2"
-    if parallel:
+    if parallel or label == "nautobot":
         command += " --parallel"
         if parallel_workers:
             command += f"={parallel_workers}"
@@ -805,8 +805,8 @@ def unittest_coverage(context):
 )
 def integration_test(
     context,
-    cache_test_fixtures=False,
-    keepdb=False,
+    cache_test_fixtures=True,
+    keepdb=True,
     label="nautobot",
     failfast=False,
     buffer=True,