Dove e come py.test cerca i fari? Ho lo stesso codice in 2 file nella stessa cartella. Quando elimino conftest.py, cmdopt non può essere trovato in esecuzione test_conf.py (anche nella stessa cartella. Perché sonoftest.py non cercata?Come e dove py.test trova i fari
# content of test_sample.py
def test_answer(cmdopt):
if cmdopt == "type1":
print ("first")
elif cmdopt == "type2":
print ("second")
assert 0 # to see what was printed
contenuto di conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption("--cmdopt", action="store", default="type1",
help="my option: type1 or type2")
@pytest.fixture
def cmdopt(request):
return request.config.getoption("--cmdopt")
contenuto sonoftest.py
import pytest
def pytest_addoption(parser):
parser.addoption("--cmdopt", action="store", default="type1",
help="my option: type1 or type2")
@pytest.fixture
def cmdopt(request):
return request.config.getoption("--cmdopt")
La documentazione dire
http://pytest.org/latest/fixture.html#fixture-function
- pytest trova il test_ehlo causa del prefisso test_. La funzione test ha bisogno di un argomento di funzione chiamato smtp. Una funzione di abbinamento viene rilevata cercando una funzione contrassegnata da fixture denominata smtp.
- smtp() viene chiamato per creare un'istanza.
- test_ehlo() viene chiamato e non riesce nell'ultima riga della funzione di test.