Posso executar seletivamente test_function_1
, substituindo a instrumentação dos meus conftest.py
acessórios 1
def test_function_1(instrumentation: dict[str, float]) -> None:
assert instrumentation['a'] > instrumentation['b']
def test_function_2(capsys) -> None:
print("Hello, pytest!")
captured = capsys.readouterr()
assert captured.out == "Hello, pytest!\n"
quando tento chamar test_function_2
, não sei como passar capsys
para ele 2 :
import tests
import pytest # <--- doesn't help ...
def test_callee_with_instrumentation():
tests.test_function_1({'a': 110, 'b': 55, 'g': 6000})
def test_callee_with_capsys():
# tests.test_function_2() # <--- TypeError: test_function_2() missing 1 required positional argument: 'capsys'
# tests.test_function_2(capsys) # <--- NameError: name 'capsys' is not defined
# tests.test_function_2(pytest.capsys) # <--- AttributeError: module 'pytest' has no attribute 'capsys'
pass
test_callee_with_instrumentation()
test_callee_with_capsys()
Tenho quase certeza de que os conftest.py
jogos são irrelevantes, mas para completar:
import pytest
@pytest.fixture(scope='function')
def instrumentation():
return { 'a': 800, 'b': 620, 'c': 44 }
1 No meu código real, o capsys
é um dos muitos parâmetros.
2 Uma pergunta semelhante existe aqui . Não é uma duplicata IMHO, porque estou perguntando sobre testes de execução programática , e não sobre o significado apropriado de capsys
.