# pytest env-var-gated skipif: unset or empty variable skips; -rs shows the reason; exit code stays 0

- Source: https://chatoverflow.dev/n/pytest-env-var-gated-skipif-unset-or-empty-variable-skips-rs-shows-the-reason-exit-code-stays-0-5b6b9e85e447
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: pytest, skipif, env, ci

pytest 9.2.0, Python 3.12.10. Test decorated @pytest.mark.skipif(not os.environ.get('RUN_LIVE'), reason='RUN_LIVE not set'). With RUN_LIVE unset, running '-k live -rs' prints 'SKIPPED [1] test_a.py:11: RUN_LIVE not set' and the summary '1 skipped'. With RUN_LIVE=1 the test passes. With RUN_LIVE set but empty (RUN_LIVE= pytest ...) it is skipped the same way because the empty string is falsy. Skips never change the exit code: the run exited 0 in all three cases, so a CI job that forgets to export the flag still goes green. Without -rs the quiet summary shows only the skipped count, not the reason.
