-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Description
Currently, PyTest detects when it is running in a CI pipeline by checking if either of the environment variables $CI
or $BUILD_NUMBER
are defined. This approach has multiple issues, all of which combine to complicate any attempt to work around the others:
- There is no way to change what env variables it checks. Your CI/CD system uses a different variable name, or worse your non-CI testing environment needs
$CI
or$BUILD_NUMBER
defined for some other reason? You're out of luck. - CI mode will be triggered if either of those variables is defined, even if the value is the empty string. Try to work around the above issue by adding
CI=${MY_CI_ENV_VAR}
to, e.g., theenvironment:
section of your docker-compose file? Nope, even if$MY_CI_ENV_VAR
is undef,$CI
will now be defined-but-empty, thus triggering CI mode. - There's no way to override CI detection manually. Want to just ignore the whole mess and add
--ci
to the command-line your CI/CD system executes, or--no-ci
in your non-CI test environment? Sorry, no such option.
The fixes to these problems are simple; implementing any one of them would break the triangle of annoyance, but all of them would be independently useful:
- Add a command-line or config option to select which env variable(s) are used for CI detection
- A command-line option can be specified in the config with
addopts
and a config option can be specified on the command-line with--override-ini
, so there's no need to add both; in this case, a config option seems the more natural choice - Be sure to allow some way for the user to specify no variables at all, thus disabling automatic CI detection
- A command-line option can be specified in the config with
- Change CI detection to only activate if the selected env variable is a non-empty string
- Stretch goal: Add an option to select what detection mode to use. Besides the existing options of 'defined' and 'nonempty', you could offer choices such as 'value equal to this given specific string' and 'anything but this given specific string'
- Add command-line or config options to manually enable or suppress CI mode, which supersede the automatic detection when present
- Again, either a command-line or config option will do; in this case, the natural choice seems to be command-line options
--ci
and--no-ci
- Again, either a command-line or config option will do; in this case, the natural choice seems to be command-line options
Metadata
Metadata
Assignees
Labels
No labels