Merge latest changes from branch 'pytest-2.7'
Conflicts: _pytest/__init__.py doc/en/fixture.rst setup.cfg testing/test_runner.py
This commit is contained in:
commit
fdd23878ec
|
@ -0,0 +1,2 @@
|
|||
#
|
||||
__version__ = '2.8.0.dev5'
|
|
@ -3,8 +3,6 @@ import bdb
|
|||
import sys
|
||||
from time import time
|
||||
|
||||
from pkg_resources import parse_version
|
||||
|
||||
import py
|
||||
import pytest
|
||||
from py._code.code import TerminalRepr
|
||||
|
@ -496,7 +494,14 @@ def importorskip(modname, minversion=None):
|
|||
if minversion is None:
|
||||
return mod
|
||||
verattr = getattr(mod, '__version__', None)
|
||||
if verattr is None or parse_version(verattr) < parse_version(minversion):
|
||||
skip("module %r has __version__ %r, required is: %r" %(
|
||||
modname, verattr, minversion))
|
||||
if minversion is not None:
|
||||
try:
|
||||
from pkg_resources import parse_version as pv
|
||||
except ImportError:
|
||||
skip("we have a required version for %r but can not import "
|
||||
"no pkg_resources to parse version strings." %(modname,))
|
||||
if verattr is None or pv(verattr) < pv(minversion):
|
||||
skip("module %r has __version__ %r, required is: %r" %(
|
||||
modname, verattr, minversion))
|
||||
return mod
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ using it::
|
|||
@pytest.fixture
|
||||
def smtp():
|
||||
import smtplib
|
||||
return smtplib.SMTP("merlinux.eu")
|
||||
return smtplib.SMTP("smtp.gmail.com")
|
||||
|
||||
def test_ehlo(smtp):
|
||||
response, msg = smtp.ehlo()
|
||||
|
@ -169,7 +169,7 @@ access the fixture function::
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def smtp():
|
||||
return smtplib.SMTP("merlinux.eu")
|
||||
return smtplib.SMTP("smtp.gmail.com")
|
||||
|
||||
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
|
||||
|
@ -178,14 +178,14 @@ function (in or below the directory where ``conftest.py`` is located)::
|
|||
# content of test_module.py
|
||||
|
||||
def test_ehlo(smtp):
|
||||
response = smtp.ehlo()
|
||||
assert response[0] == 250
|
||||
assert "merlinux" in response[1]
|
||||
response, msg = smtp.ehlo()
|
||||
assert response == 250
|
||||
assert "smtp.gmail.com" in str(msg, 'ascii')
|
||||
assert 0 # for demo purposes
|
||||
|
||||
def test_noop(smtp):
|
||||
response = smtp.noop()
|
||||
assert response[0] == 250
|
||||
response, msg = smtp.noop()
|
||||
assert response == 250
|
||||
assert 0 # for demo purposes
|
||||
|
||||
We deliberately insert failing ``assert 0`` statements in order to
|
||||
|
@ -258,7 +258,7 @@ or multiple times::
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def smtp(request):
|
||||
smtp = smtplib.SMTP("merlinux.eu")
|
||||
smtp = smtplib.SMTP("smtp.gmail.com")
|
||||
def fin():
|
||||
print ("teardown smtp")
|
||||
smtp.close()
|
||||
|
@ -299,7 +299,7 @@ read an optional server URL from the test module which uses our fixture::
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def smtp(request):
|
||||
server = getattr(request.module, "smtpserver", "merlinux.eu")
|
||||
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
|
||||
smtp = smtplib.SMTP(server)
|
||||
|
||||
def fin():
|
||||
|
@ -363,7 +363,7 @@ through the special :py:class:`request <FixtureRequest>` object::
|
|||
import smtplib
|
||||
|
||||
@pytest.fixture(scope="module",
|
||||
params=["merlinux.eu", "mail.python.org"])
|
||||
params=["smtp.gmail.com", "mail.python.org"])
|
||||
def smtp(request):
|
||||
smtp = smtplib.SMTP(request.param)
|
||||
def fin():
|
||||
|
@ -436,7 +436,7 @@ connection the second test fails in ``test_ehlo`` because a
|
|||
different server string is expected than what arrived.
|
||||
|
||||
pytest will build a string that is the test ID for each fixture value
|
||||
in a parametrized fixture, e.g. ``test_ehlo[merlinux.eu]`` and
|
||||
in a parametrized fixture, e.g. ``test_ehlo[smtp.gmail.com]`` and
|
||||
``test_ehlo[mail.python.org]`` in the above examples. These IDs can
|
||||
be used with ``-k`` to select specific cases to run, and they will
|
||||
also identify the specific case when one is failing. Running pytest
|
||||
|
@ -448,6 +448,7 @@ make a string based on the argument name. It is possible to customise
|
|||
the string used in a test ID for a certain fixture value by using the
|
||||
``ids`` keyword argument::
|
||||
|
||||
# content of test_ids.py
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[0, 1], ids=["spam", "ham"])
|
||||
|
|
Loading…
Reference in New Issue