Skip to content

Proper "ignore test depending on env" handling #139

@crepererum

Description

@crepererum
Collaborator

Abstract

We want to skip tests if certain environment variables are NOT set (e.g. SOCKS_PROXY) so that developers do not need to provide a full-blown integration test infrastructure if they only work on a subset of the features.

ACs

  • tests are skipped when environment variables are NOT set
  • tests are skipped at runtime, NOT at compile time
  • skipped tests are marked as "ignored"
  • tests skipping requires little code (ideally a single line in form of a decorator, a function call, a macro call)

Current Situation

We currently use macros like this:

/// Get the Socks Proxy environment variable.
///
/// If `SOCKS_PROXY` is not set, fail the tests and provide
/// guidance for setting `SOCKS_PROXY`.
#[macro_export]
macro_rules! maybe_skip_SOCKS_PROXY {
() => {{
use std::env;
dotenv::dotenv().ok();
match (env::var("SOCKS_PROXY").ok()) {
Some(proxy) => proxy,
_ => {
eprintln!("skipping integration tests with Proxy - set SOCKS_PROXY to run");
return;
}
}
}};
}

This fulfills all ACs except for skipped tests are marked as "ignored".

References

Activity

crepererum

crepererum commented on May 24, 2022

@crepererum
CollaboratorAuthor

@mario-s volunteered to work on this 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @crepererum

        Issue actions

          Proper "ignore test depending on env" handling · Issue #139 · influxdata/rskafka