Skip to content

CI Pipeline Detection Issues #13766

@macdjord

Description

@macdjord

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:

  1. 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.
  2. 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., the environment: 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.
  3. 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:

  1. 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
  2. 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'
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions