Merge remote-tracking branch 'upstream/pytest-2.7'
Conflicts: testing/conftest.py
This commit is contained in:
commit
9f94e443ff
|
@ -104,9 +104,17 @@
|
||||||
2.7.3 (compared to 2.7.2)
|
2.7.3 (compared to 2.7.2)
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
- Allow 'dev', 'rc', or other non-integer version strings in `importorskip`.
|
||||||
|
Thanks to Eric Hunsberger for the PR.
|
||||||
|
|
||||||
- fix issue856: consider --color parameter in all outputs (for example
|
- fix issue856: consider --color parameter in all outputs (for example
|
||||||
--fixtures). Thanks Barney Gale for the report and Bruno Oliveira for the PR.
|
--fixtures). Thanks Barney Gale for the report and Bruno Oliveira for the PR.
|
||||||
|
|
||||||
|
- fix issue855: passing str objects as `plugins` argument to pytest.main
|
||||||
|
is now interpreted as a module name to be imported and registered as a
|
||||||
|
plugin, instead of silently having no effect.
|
||||||
|
Thanks xmo-odoo for the report and Bruno Oliveira for the PR.
|
||||||
|
|
||||||
- fix issue744: fix for ast.Call changes in Python 3.5+. Thanks
|
- fix issue744: fix for ast.Call changes in Python 3.5+. Thanks
|
||||||
Guido van Rossum, Matthias Bussonnier, Stefan Zimmermann and
|
Guido van Rossum, Matthias Bussonnier, Stefan Zimmermann and
|
||||||
Thomas Kluyver.
|
Thomas Kluyver.
|
||||||
|
|
|
@ -107,6 +107,9 @@ def _prepareconfig(args=None, plugins=None):
|
||||||
try:
|
try:
|
||||||
if plugins:
|
if plugins:
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
|
if isinstance(plugin, py.builtin._basestring):
|
||||||
|
pluginmanager.consider_pluginarg(plugin)
|
||||||
|
else:
|
||||||
pluginmanager.register(plugin)
|
pluginmanager.register(plugin)
|
||||||
return pluginmanager.hook.pytest_cmdline_parse(
|
return pluginmanager.hook.pytest_cmdline_parse(
|
||||||
pluginmanager=pluginmanager, args=args)
|
pluginmanager=pluginmanager, args=args)
|
||||||
|
|
|
@ -3,6 +3,8 @@ import bdb
|
||||||
import sys
|
import sys
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
from pkg_resources import parse_version
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
from py._code.code import TerminalRepr
|
from py._code.code import TerminalRepr
|
||||||
|
@ -483,8 +485,6 @@ def importorskip(modname, minversion=None):
|
||||||
""" return imported module if it has at least "minversion" as its
|
""" return imported module if it has at least "minversion" as its
|
||||||
__version__ attribute. If no minversion is specified the a skip
|
__version__ attribute. If no minversion is specified the a skip
|
||||||
is only triggered if the module can not be imported.
|
is only triggered if the module can not be imported.
|
||||||
Note that version comparison only works with simple version strings
|
|
||||||
like "1.2.3" but not "1.2.3.dev1" or others.
|
|
||||||
"""
|
"""
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
compile(modname, '', 'eval') # to catch syntaxerrors
|
compile(modname, '', 'eval') # to catch syntaxerrors
|
||||||
|
@ -496,9 +496,7 @@ def importorskip(modname, minversion=None):
|
||||||
if minversion is None:
|
if minversion is None:
|
||||||
return mod
|
return mod
|
||||||
verattr = getattr(mod, '__version__', None)
|
verattr = getattr(mod, '__version__', None)
|
||||||
def intver(verstring):
|
if verattr is None or parse_version(verattr) < parse_version(minversion):
|
||||||
return [int(x) for x in verstring.split(".")]
|
|
||||||
if verattr is None or intver(verattr) < intver(minversion):
|
|
||||||
skip("module %r has __version__ %r, required is: %r" %(
|
skip("module %r has __version__ %r, required is: %r" %(
|
||||||
modname, verattr, minversion))
|
modname, verattr, minversion))
|
||||||
return mod
|
return mod
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
import py, pytest
|
import py, pytest
|
||||||
|
|
||||||
class TestGeneralUsage:
|
class TestGeneralUsage:
|
||||||
|
@ -371,6 +372,21 @@ class TestGeneralUsage:
|
||||||
"*fixture 'invalid_fixture' not found",
|
"*fixture 'invalid_fixture' not found",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_plugins_given_as_strings(self, tmpdir, monkeypatch):
|
||||||
|
"""test that str values passed to main() as `plugins` arg
|
||||||
|
are interpreted as module names to be imported and registered.
|
||||||
|
#855.
|
||||||
|
"""
|
||||||
|
with pytest.raises(ImportError) as excinfo:
|
||||||
|
pytest.main([str(tmpdir)], plugins=['invalid.module'])
|
||||||
|
assert 'invalid' in str(excinfo.value)
|
||||||
|
|
||||||
|
p = tmpdir.join('test_test_plugins_given_as_strings.py')
|
||||||
|
p.write('def test_foo(): pass')
|
||||||
|
mod = py.std.types.ModuleType("myplugin")
|
||||||
|
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
||||||
|
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
||||||
|
|
||||||
|
|
||||||
class TestInvocationVariants:
|
class TestInvocationVariants:
|
||||||
def test_earlyinit(self, testdir):
|
def test_earlyinit(self, testdir):
|
||||||
|
|
|
@ -649,7 +649,8 @@ def lsof_check():
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
try:
|
try:
|
||||||
out = py.process.cmdexec("lsof -p %d" % pid)
|
out = py.process.cmdexec("lsof -p %d" % pid)
|
||||||
except py.process.cmdexec.Error:
|
except (py.process.cmdexec.Error, UnicodeDecodeError):
|
||||||
|
# about UnicodeDecodeError, see note on conftest.py
|
||||||
pytest.skip("could not run 'lsof'")
|
pytest.skip("could not run 'lsof'")
|
||||||
yield
|
yield
|
||||||
out2 = py.process.cmdexec("lsof -p %d" % pid)
|
out2 = py.process.cmdexec("lsof -p %d" % pid)
|
||||||
|
|
|
@ -439,7 +439,7 @@ def test_exception_printing_skip():
|
||||||
s = excinfo.exconly(tryshort=True)
|
s = excinfo.exconly(tryshort=True)
|
||||||
assert s.startswith("Skipped")
|
assert s.startswith("Skipped")
|
||||||
|
|
||||||
def test_importorskip():
|
def test_importorskip(monkeypatch):
|
||||||
importorskip = pytest.importorskip
|
importorskip = pytest.importorskip
|
||||||
def f():
|
def f():
|
||||||
importorskip("asdlkj")
|
importorskip("asdlkj")
|
||||||
|
@ -457,7 +457,7 @@ def test_importorskip():
|
||||||
pytest.raises(SyntaxError, "pytest.importorskip('x=y')")
|
pytest.raises(SyntaxError, "pytest.importorskip('x=y')")
|
||||||
mod = py.std.types.ModuleType("hello123")
|
mod = py.std.types.ModuleType("hello123")
|
||||||
mod.__version__ = "1.3"
|
mod.__version__ = "1.3"
|
||||||
sys.modules["hello123"] = mod
|
monkeypatch.setitem(sys.modules, "hello123", mod)
|
||||||
pytest.raises(pytest.skip.Exception, """
|
pytest.raises(pytest.skip.Exception, """
|
||||||
pytest.importorskip("hello123", minversion="1.3.1")
|
pytest.importorskip("hello123", minversion="1.3.1")
|
||||||
""")
|
""")
|
||||||
|
@ -471,6 +471,19 @@ def test_importorskip_imports_last_module_part():
|
||||||
ospath = pytest.importorskip("os.path")
|
ospath = pytest.importorskip("os.path")
|
||||||
assert os.path == ospath
|
assert os.path == ospath
|
||||||
|
|
||||||
|
def test_importorskip_dev_module(monkeypatch):
|
||||||
|
try:
|
||||||
|
mod = py.std.types.ModuleType("mockmodule")
|
||||||
|
mod.__version__ = '0.13.0.dev-43290'
|
||||||
|
monkeypatch.setitem(sys.modules, 'mockmodule', mod)
|
||||||
|
mod2 = pytest.importorskip('mockmodule', minversion='0.12.0')
|
||||||
|
assert mod2 == mod
|
||||||
|
pytest.raises(pytest.skip.Exception, """
|
||||||
|
pytest.importorskip('mockmodule1', minversion='0.14.0')""")
|
||||||
|
except pytest.skip.Exception:
|
||||||
|
print(py.code.ExceptionInfo())
|
||||||
|
pytest.fail("spurious skip")
|
||||||
|
|
||||||
|
|
||||||
def test_pytest_cmdline_main(testdir):
|
def test_pytest_cmdline_main(testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue