Fix SMTP port in fixture docs
Also add timeout to avoid regen getting stuck due to connection problems Fix #2509
This commit is contained in:
parent
6908d93ba1
commit
7277fbdb20
|
@ -57,7 +57,7 @@ using it::
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def smtp():
|
def smtp():
|
||||||
import smtplib
|
import smtplib
|
||||||
return smtplib.SMTP("smtp.gmail.com")
|
return smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
|
||||||
|
|
||||||
def test_ehlo(smtp):
|
def test_ehlo(smtp):
|
||||||
response, msg = smtp.ehlo()
|
response, msg = smtp.ehlo()
|
||||||
|
@ -157,7 +157,7 @@ access the fixture function::
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def smtp():
|
def smtp():
|
||||||
return smtplib.SMTP("smtp.gmail.com")
|
return smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
|
||||||
|
|
||||||
The name of the fixture again is ``smtp`` and you can access its result by
|
The name of the fixture again is ``smtp`` and you can access its result by
|
||||||
listing the name ``smtp`` as an input parameter in any test or fixture
|
listing the name ``smtp`` as an input parameter in any test or fixture
|
||||||
|
@ -247,7 +247,7 @@ the code after the *yield* statement serves as the teardown code:
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def smtp():
|
def smtp():
|
||||||
smtp = smtplib.SMTP("smtp.gmail.com")
|
smtp = smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
|
||||||
yield smtp # provide the fixture value
|
yield smtp # provide the fixture value
|
||||||
print("teardown smtp")
|
print("teardown smtp")
|
||||||
smtp.close()
|
smtp.close()
|
||||||
|
@ -281,7 +281,7 @@ Note that we can also seamlessly use the ``yield`` syntax with ``with`` statemen
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def smtp():
|
def smtp():
|
||||||
with smtplib.SMTP("smtp.gmail.com") as smtp:
|
with smtplib.SMTP("smtp.gmail.com", 587, timeout=5) as smtp:
|
||||||
yield smtp # provide the fixture value
|
yield smtp # provide the fixture value
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ Here's the ``smtp`` fixture changed to use ``addfinalizer`` for cleanup:
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def smtp(request):
|
def smtp(request):
|
||||||
smtp = smtplib.SMTP("smtp.gmail.com")
|
smtp = smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
|
||||||
def fin():
|
def fin():
|
||||||
print ("teardown smtp")
|
print ("teardown smtp")
|
||||||
smtp.close()
|
smtp.close()
|
||||||
|
@ -362,7 +362,7 @@ read an optional server URL from the test module which uses our fixture::
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def smtp(request):
|
def smtp(request):
|
||||||
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
|
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
|
||||||
smtp = smtplib.SMTP(server)
|
smtp = smtplib.SMTP(server, 587, timeout=5)
|
||||||
yield smtp
|
yield smtp
|
||||||
print ("finalizing %s (%s)" % (smtp, server))
|
print ("finalizing %s (%s)" % (smtp, server))
|
||||||
smtp.close()
|
smtp.close()
|
||||||
|
@ -426,7 +426,7 @@ through the special :py:class:`request <FixtureRequest>` object::
|
||||||
@pytest.fixture(scope="module",
|
@pytest.fixture(scope="module",
|
||||||
params=["smtp.gmail.com", "mail.python.org"])
|
params=["smtp.gmail.com", "mail.python.org"])
|
||||||
def smtp(request):
|
def smtp(request):
|
||||||
smtp = smtplib.SMTP(request.param)
|
smtp = smtplib.SMTP(request.param, 587, timeout=5)
|
||||||
yield smtp
|
yield smtp
|
||||||
print ("finalizing %s" % smtp)
|
print ("finalizing %s" % smtp)
|
||||||
smtp.close()
|
smtp.close()
|
||||||
|
|
Loading…
Reference in New Issue