Skip to content

Instantly share code, notes, and snippets.

@sgibson91
Last active August 6, 2021 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgibson91/5b31ee1b18832ae785565da99fe605a2 to your computer and use it in GitHub Desktop.
Save sgibson91/5b31ee1b18832ae785565da99fe605a2 to your computer and use it in GitHub Desktop.
Testing pytest exposing params

Test pytest exposing params

Running the following command:

pytest -q --secret-input SUPER_SECRET_VALUE

produces the following output

F                                                                                                                                                                                              [100%]
============================================================================================== FAILURES ==============================================================================================
_________________________________________________________________________________________ test_failing_func __________________________________________________________________________________________

secret_input = 'SUPER_SECRET_VALUE'

    def test_failing_func(secret_input):
>       assert False
E       assert False

tests/test_fail.py:2: AssertionError
====================================================================================== short test summary info =======================================================================================
FAILED tests/test_fail.py::test_failing_func - assert False
1 failed in 0.11s

whereas running

pytest -q --secret-input SUPER_SECRET_VALUE --tb=short

suppresses the printing of the secret_input

F                                                                                                                                                                                              [100%]
============================================================================================== FAILURES ==============================================================================================
_________________________________________________________________________________________ test_failing_func __________________________________________________________________________________________
tests/test_fail.py:2: in test_failing_func
    assert False
E   assert False
====================================================================================== short test summary info =======================================================================================
FAILED tests/test_fail.py::test_failing_func - assert False
1 failed in 0.10s
# Define the input options to pytest
import pytest
def pytest_addoption(parser):
parser.addoption(
"--secret-input",
action="store"
)
@pytest.fixture
def secret_input(request):
return request.config.getoption('--secret-input')
# This test takes an input and fails
def test_failing_test(secret_input):
assert False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment