pytest Compatibility
testing as part of your existing pytest test suite.testing is built to seamlessly integrate with pytest. In fact, all test discovery and execution is done through pytest itself, which means the invariant test command can be considered a pytest equivalent entry point.
The invariant test CLI
invariant test is a lightweight wrapper of the original pytest CLI. It is designed to be a drop-in replacement for pytest in your existing test suite.
On top of the standard pytest arguments, invariant test supports the following extra arguments to enable pushing to Explorer.
Extra Arguments
The name of the dataset to be used to associate the test trace data and results. This name will be used to derive a fresh dataset name on each run (e.g. myproject-1732007573)
Flag to indicate whether to push data to Explorer. If set to true,
the INVARIANT_API_KEY environment variable must be set. Visit the Explorer Documentation to learn how to obtain your own API key.
Example Commands
Run all tests in a directory:
Run all tests in a file:
Run a specific test:
Run all tests in a directory and push data to Explorer:
Run all tests in a file and push data to Explorer (dataset name is myproject):
Apart from these basic examples, you can use any other pytest arguments as well. For more information, refer to the pytest documentation.
Running with pytest directly
If you prefer to run pytest directly, you can do so by running the following command:
This will run all tests, including testing agent test cases. Note however, that when running pytest directly, the --push and --dataset_name arguments are not supported and you won't be able to push test results to Explorer.
For more information on pytest, refer to the pytest documentation.