Replace py.std with stdlib imports
This commit is contained in:
parent
962aede290
commit
bd1d17e8de
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
||||||
import re
|
import re
|
||||||
from weakref import ref
|
from weakref import ref
|
||||||
|
@ -422,7 +424,7 @@ class ExceptionInfo(object):
|
||||||
"""
|
"""
|
||||||
if style == 'native':
|
if style == 'native':
|
||||||
return ReprExceptionInfo(ReprTracebackNative(
|
return ReprExceptionInfo(ReprTracebackNative(
|
||||||
py.std.traceback.format_exception(
|
traceback.format_exception(
|
||||||
self.type,
|
self.type,
|
||||||
self.value,
|
self.value,
|
||||||
self.traceback[0]._rawentry,
|
self.traceback[0]._rawentry,
|
||||||
|
@ -556,7 +558,7 @@ class FormattedExcinfo(object):
|
||||||
# else:
|
# else:
|
||||||
# self._line("%-10s =\\" % (name,))
|
# self._line("%-10s =\\" % (name,))
|
||||||
# # XXX
|
# # XXX
|
||||||
# py.std.pprint.pprint(value, stream=self.excinfowriter)
|
# pprint.pprint(value, stream=self.excinfowriter)
|
||||||
return ReprLocals(lines)
|
return ReprLocals(lines)
|
||||||
|
|
||||||
def repr_traceback_entry(self, entry, excinfo=None):
|
def repr_traceback_entry(self, entry, excinfo=None):
|
||||||
|
@ -669,7 +671,7 @@ class FormattedExcinfo(object):
|
||||||
else:
|
else:
|
||||||
# fallback to native repr if the exception doesn't have a traceback:
|
# fallback to native repr if the exception doesn't have a traceback:
|
||||||
# ExceptionInfo objects require a full traceback to work
|
# ExceptionInfo objects require a full traceback to work
|
||||||
reprtraceback = ReprTracebackNative(py.std.traceback.format_exception(type(e), e, None))
|
reprtraceback = ReprTracebackNative(traceback.format_exception(type(e), e, None))
|
||||||
reprcrash = None
|
reprcrash = None
|
||||||
|
|
||||||
repr_chain += [(reprtraceback, reprcrash, descr)]
|
repr_chain += [(reprtraceback, reprcrash, descr)]
|
||||||
|
@ -886,7 +888,7 @@ def getrawcode(obj, trycall=True):
|
||||||
obj = getattr(obj, 'f_code', obj)
|
obj = getattr(obj, 'f_code', obj)
|
||||||
obj = getattr(obj, '__code__', obj)
|
obj = getattr(obj, '__code__', obj)
|
||||||
if trycall and not hasattr(obj, 'co_firstlineno'):
|
if trycall and not hasattr(obj, 'co_firstlineno'):
|
||||||
if hasattr(obj, '__call__') and not py.std.inspect.isclass(obj):
|
if hasattr(obj, '__call__') and not inspect.isclass(obj):
|
||||||
x = getrawcode(obj.__call__, trycall=False)
|
x = getrawcode(obj.__call__, trycall=False)
|
||||||
if hasattr(x, 'co_firstlineno'):
|
if hasattr(x, 'co_firstlineno'):
|
||||||
return x
|
return x
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import, division, generators, print_function
|
||||||
import ast
|
import ast
|
||||||
from ast import PyCF_ONLY_AST as _AST_FLAG
|
from ast import PyCF_ONLY_AST as _AST_FLAG
|
||||||
from bisect import bisect_right
|
from bisect import bisect_right
|
||||||
|
import linecache
|
||||||
import sys
|
import sys
|
||||||
import six
|
import six
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -191,7 +192,7 @@ class Source(object):
|
||||||
if flag & _AST_FLAG:
|
if flag & _AST_FLAG:
|
||||||
return co
|
return co
|
||||||
lines = [(x + "\n") for x in self.lines]
|
lines = [(x + "\n") for x in self.lines]
|
||||||
py.std.linecache.cache[filename] = (1, None, lines, filename)
|
linecache.cache[filename] = (1, None, lines, filename)
|
||||||
return co
|
return co
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -223,8 +224,7 @@ def getfslineno(obj):
|
||||||
code = _pytest._code.Code(obj)
|
code = _pytest._code.Code(obj)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
fn = (py.std.inspect.getsourcefile(obj) or
|
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
|
||||||
py.std.inspect.getfile(obj))
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return "", -1
|
return "", -1
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ def getfslineno(obj):
|
||||||
|
|
||||||
def findsource(obj):
|
def findsource(obj):
|
||||||
try:
|
try:
|
||||||
sourcelines, lineno = py.std.inspect.findsource(obj)
|
sourcelines, lineno = inspect.findsource(obj)
|
||||||
except py.builtin._sysex:
|
except py.builtin._sysex:
|
||||||
raise
|
raise
|
||||||
except: # noqa
|
except: # noqa
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Replace py.std with stdlib imports.
|
|
@ -159,10 +159,10 @@ class TestRaises(object):
|
||||||
def test_dynamic_compile_shows_nicely():
|
def test_dynamic_compile_shows_nicely():
|
||||||
src = 'def foo():\n assert 1 == 0\n'
|
src = 'def foo():\n assert 1 == 0\n'
|
||||||
name = 'abc-123'
|
name = 'abc-123'
|
||||||
module = py.std.imp.new_module(name)
|
module = imp.new_module(name)
|
||||||
code = _pytest._code.compile(src, name, 'exec')
|
code = _pytest._code.compile(src, name, 'exec')
|
||||||
py.builtin.exec_(code, module.__dict__)
|
py.builtin.exec_(code, module.__dict__)
|
||||||
py.std.sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
module.foo()
|
module.foo()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -413,10 +413,10 @@ get on the terminal - we are working on that)::
|
||||||
def test_dynamic_compile_shows_nicely():
|
def test_dynamic_compile_shows_nicely():
|
||||||
src = 'def foo():\n assert 1 == 0\n'
|
src = 'def foo():\n assert 1 == 0\n'
|
||||||
name = 'abc-123'
|
name = 'abc-123'
|
||||||
module = py.std.imp.new_module(name)
|
module = imp.new_module(name)
|
||||||
code = _pytest._code.compile(src, name, 'exec')
|
code = _pytest._code.compile(src, name, 'exec')
|
||||||
py.builtin.exec_(code, module.__dict__)
|
py.builtin.exec_(code, module.__dict__)
|
||||||
py.std.sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
> module.foo()
|
> module.foo()
|
||||||
|
|
||||||
failure_demo.py:166:
|
failure_demo.py:166:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import json
|
import json
|
||||||
import py
|
import py
|
||||||
import textwrap
|
|
||||||
|
|
||||||
issues_url = "https://api.github.com/repos/pytest-dev/pytest/issues"
|
issues_url = "https://api.github.com/repos/pytest-dev/pytest/issues"
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -398,7 +399,7 @@ class TestGeneralUsage(object):
|
||||||
|
|
||||||
p = tmpdir.join('test_test_plugins_given_as_strings.py')
|
p = tmpdir.join('test_test_plugins_given_as_strings.py')
|
||||||
p.write('def test_foo(): pass')
|
p.write('def test_foo(): pass')
|
||||||
mod = py.std.types.ModuleType("myplugin")
|
mod = types.ModuleType("myplugin")
|
||||||
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
monkeypatch.setitem(sys.modules, 'myplugin', mod)
|
||||||
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0
|
||||||
|
|
||||||
|
@ -492,17 +493,17 @@ class TestInvocationVariants(object):
|
||||||
|
|
||||||
def test_python_minus_m_invocation_ok(self, testdir):
|
def test_python_minus_m_invocation_ok(self, testdir):
|
||||||
p1 = testdir.makepyfile("def test_hello(): pass")
|
p1 = testdir.makepyfile("def test_hello(): pass")
|
||||||
res = testdir.run(py.std.sys.executable, "-m", "pytest", str(p1))
|
res = testdir.run(sys.executable, "-m", "pytest", str(p1))
|
||||||
assert res.ret == 0
|
assert res.ret == 0
|
||||||
|
|
||||||
def test_python_minus_m_invocation_fail(self, testdir):
|
def test_python_minus_m_invocation_fail(self, testdir):
|
||||||
p1 = testdir.makepyfile("def test_fail(): 0/0")
|
p1 = testdir.makepyfile("def test_fail(): 0/0")
|
||||||
res = testdir.run(py.std.sys.executable, "-m", "pytest", str(p1))
|
res = testdir.run(sys.executable, "-m", "pytest", str(p1))
|
||||||
assert res.ret == 1
|
assert res.ret == 1
|
||||||
|
|
||||||
def test_python_pytest_package(self, testdir):
|
def test_python_pytest_package(self, testdir):
|
||||||
p1 = testdir.makepyfile("def test_pass(): pass")
|
p1 = testdir.makepyfile("def test_pass(): pass")
|
||||||
res = testdir.run(py.std.sys.executable, "-m", "pytest", str(p1))
|
res = testdir.run(sys.executable, "-m", "pytest", str(p1))
|
||||||
assert res.ret == 0
|
assert res.ret == 0
|
||||||
res.stdout.fnmatch_lines(["*1 passed*"])
|
res.stdout.fnmatch_lines(["*1 passed*"])
|
||||||
|
|
||||||
|
@ -560,7 +561,7 @@ class TestInvocationVariants(object):
|
||||||
])
|
])
|
||||||
|
|
||||||
def join_pythonpath(what):
|
def join_pythonpath(what):
|
||||||
cur = py.std.os.environ.get('PYTHONPATH')
|
cur = os.environ.get('PYTHONPATH')
|
||||||
if cur:
|
if cur:
|
||||||
return str(what) + os.pathsep + cur
|
return str(what) + os.pathsep + cur
|
||||||
return what
|
return what
|
||||||
|
@ -618,7 +619,7 @@ class TestInvocationVariants(object):
|
||||||
# └── test_world.py
|
# └── test_world.py
|
||||||
|
|
||||||
def join_pythonpath(*dirs):
|
def join_pythonpath(*dirs):
|
||||||
cur = py.std.os.environ.get('PYTHONPATH')
|
cur = os.environ.get('PYTHONPATH')
|
||||||
if cur:
|
if cur:
|
||||||
dirs += (cur,)
|
dirs += (cur,)
|
||||||
return os.pathsep.join(str(p) for p in dirs)
|
return os.pathsep.join(str(p) for p in dirs)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import _pytest
|
import _pytest
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -472,7 +474,7 @@ class TestFormattedExcinfo(object):
|
||||||
excinfo = _pytest._code.ExceptionInfo()
|
excinfo = _pytest._code.ExceptionInfo()
|
||||||
repr = pr.repr_excinfo(excinfo)
|
repr = pr.repr_excinfo(excinfo)
|
||||||
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
|
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert repr.chain[0][0].reprentries[1].lines[0] == "> ???"
|
assert repr.chain[0][0].reprentries[1].lines[0] == "> ???"
|
||||||
|
|
||||||
def test_repr_many_line_source_not_existing(self):
|
def test_repr_many_line_source_not_existing(self):
|
||||||
|
@ -487,7 +489,7 @@ raise ValueError()
|
||||||
excinfo = _pytest._code.ExceptionInfo()
|
excinfo = _pytest._code.ExceptionInfo()
|
||||||
repr = pr.repr_excinfo(excinfo)
|
repr = pr.repr_excinfo(excinfo)
|
||||||
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
|
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert repr.chain[0][0].reprentries[1].lines[0] == "> ???"
|
assert repr.chain[0][0].reprentries[1].lines[0] == "> ???"
|
||||||
|
|
||||||
def test_repr_source_failing_fullsource(self):
|
def test_repr_source_failing_fullsource(self):
|
||||||
|
@ -545,13 +547,13 @@ raise ValueError()
|
||||||
fail = IOError()
|
fail = IOError()
|
||||||
repr = pr.repr_excinfo(excinfo)
|
repr = pr.repr_excinfo(excinfo)
|
||||||
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
|
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert repr.chain[0][0].reprentries[0].lines[0] == "> ???"
|
assert repr.chain[0][0].reprentries[0].lines[0] == "> ???"
|
||||||
|
|
||||||
fail = py.error.ENOENT # noqa
|
fail = py.error.ENOENT # noqa
|
||||||
repr = pr.repr_excinfo(excinfo)
|
repr = pr.repr_excinfo(excinfo)
|
||||||
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
|
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert repr.chain[0][0].reprentries[0].lines[0] == "> ???"
|
assert repr.chain[0][0].reprentries[0].lines[0] == "> ???"
|
||||||
|
|
||||||
def test_repr_local(self):
|
def test_repr_local(self):
|
||||||
|
@ -738,7 +740,7 @@ raise ValueError()
|
||||||
repr = p.repr_excinfo(excinfo)
|
repr = p.repr_excinfo(excinfo)
|
||||||
assert repr.reprtraceback
|
assert repr.reprtraceback
|
||||||
assert len(repr.reprtraceback.reprentries) == len(reprtb.reprentries)
|
assert len(repr.reprtraceback.reprentries) == len(reprtb.reprentries)
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert repr.chain[0][0]
|
assert repr.chain[0][0]
|
||||||
assert len(repr.chain[0][0].reprentries) == len(reprtb.reprentries)
|
assert len(repr.chain[0][0].reprentries) == len(reprtb.reprentries)
|
||||||
assert repr.reprcrash.path.endswith("mod.py")
|
assert repr.reprcrash.path.endswith("mod.py")
|
||||||
|
@ -758,7 +760,7 @@ raise ValueError()
|
||||||
def raiseos():
|
def raiseos():
|
||||||
raise OSError(2)
|
raise OSError(2)
|
||||||
|
|
||||||
monkeypatch.setattr(py.std.os, 'getcwd', raiseos)
|
monkeypatch.setattr(os, 'getcwd', raiseos)
|
||||||
assert p._makepath(__file__) == __file__
|
assert p._makepath(__file__) == __file__
|
||||||
p.repr_traceback(excinfo)
|
p.repr_traceback(excinfo)
|
||||||
|
|
||||||
|
@ -816,10 +818,10 @@ raise ValueError()
|
||||||
for style in ("short", "long", "no"):
|
for style in ("short", "long", "no"):
|
||||||
for showlocals in (True, False):
|
for showlocals in (True, False):
|
||||||
repr = excinfo.getrepr(style=style, showlocals=showlocals)
|
repr = excinfo.getrepr(style=style, showlocals=showlocals)
|
||||||
if py.std.sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
assert isinstance(repr, ReprExceptionInfo)
|
assert isinstance(repr, ReprExceptionInfo)
|
||||||
assert repr.reprtraceback.style == style
|
assert repr.reprtraceback.style == style
|
||||||
if py.std.sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
assert isinstance(repr, ExceptionChainRepr)
|
assert isinstance(repr, ExceptionChainRepr)
|
||||||
for repr in repr.chain:
|
for repr in repr.chain:
|
||||||
assert repr[0].style == style
|
assert repr[0].style == style
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# disable flake check on this file because some constructs are strange
|
# disable flake check on this file because some constructs are strange
|
||||||
# or redundant on purpose and can't be disable on a line-by-line basis
|
# or redundant on purpose and can't be disable on a line-by-line basis
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
@ -187,9 +188,9 @@ class TestSourceParsingAndCompiling(object):
|
||||||
def f():
|
def f():
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
""")
|
""")
|
||||||
source1 = py.std.inspect.getsource(co1)
|
source1 = inspect.getsource(co1)
|
||||||
assert 'KeyError' in source1
|
assert 'KeyError' in source1
|
||||||
source2 = py.std.inspect.getsource(co2)
|
source2 = inspect.getsource(co2)
|
||||||
assert 'ValueError' in source2
|
assert 'ValueError' in source2
|
||||||
|
|
||||||
def test_getstatement(self):
|
def test_getstatement(self):
|
||||||
|
@ -373,7 +374,6 @@ def test_deindent():
|
||||||
c = '''while True:
|
c = '''while True:
|
||||||
pass
|
pass
|
||||||
'''
|
'''
|
||||||
import inspect
|
|
||||||
lines = deindent(inspect.getsource(f).splitlines())
|
lines = deindent(inspect.getsource(f).splitlines())
|
||||||
assert lines == ["def f():", " c = '''while True:", " pass", "'''"]
|
assert lines == ["def f():", " c = '''while True:", " pass", "'''"]
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ def test_getfslineno():
|
||||||
|
|
||||||
fspath, lineno = getfslineno(A)
|
fspath, lineno = getfslineno(A)
|
||||||
|
|
||||||
_, A_lineno = py.std.inspect.findsource(A)
|
_, A_lineno = inspect.findsource(A)
|
||||||
assert fspath.basename == "test_source.py"
|
assert fspath.basename == "test_source.py"
|
||||||
assert lineno == A_lineno
|
assert lineno == A_lineno
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import py
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.main import (
|
from _pytest.main import (
|
||||||
Collector,
|
Collector,
|
||||||
|
@ -25,7 +24,7 @@ class TestModule(object):
|
||||||
b = testdir.mkdir("b")
|
b = testdir.mkdir("b")
|
||||||
p = a.ensure("test_whatever.py")
|
p = a.ensure("test_whatever.py")
|
||||||
p.pyimport()
|
p.pyimport()
|
||||||
del py.std.sys.modules['test_whatever']
|
del sys.modules['test_whatever']
|
||||||
b.ensure("test_whatever.py")
|
b.ensure("test_whatever.py")
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
|
@ -754,7 +753,7 @@ class TestSorting(object):
|
||||||
|
|
||||||
assert fn1 == fn2
|
assert fn1 == fn2
|
||||||
assert fn1 != modcol
|
assert fn1 != modcol
|
||||||
if py.std.sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
assert cmp(fn1, fn2) == 0
|
assert cmp(fn1, fn2) == 0
|
||||||
assert hash(fn1) == hash(fn2)
|
assert hash(fn1) == hash(fn2)
|
||||||
|
|
||||||
|
|
|
@ -730,7 +730,7 @@ class TestMetafuncFunctional(object):
|
||||||
def test_attributes(self, testdir):
|
def test_attributes(self, testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
# assumes that generate/provide runs in the same process
|
# assumes that generate/provide runs in the same process
|
||||||
import py, pytest
|
import sys, pytest
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
metafunc.addcall(param=metafunc)
|
metafunc.addcall(param=metafunc)
|
||||||
|
|
||||||
|
@ -749,7 +749,7 @@ class TestMetafuncFunctional(object):
|
||||||
def test_method(self, metafunc, pytestconfig):
|
def test_method(self, metafunc, pytestconfig):
|
||||||
assert metafunc.config == pytestconfig
|
assert metafunc.config == pytestconfig
|
||||||
assert metafunc.module.__name__ == __name__
|
assert metafunc.module.__name__ == __name__
|
||||||
if py.std.sys.version_info > (3, 0):
|
if sys.version_info > (3, 0):
|
||||||
unbound = TestClass.test_method
|
unbound = TestClass.test_method
|
||||||
else:
|
else:
|
||||||
unbound = TestClass.test_method.im_func
|
unbound = TestClass.test_method.im_func
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import py
|
import subprocess
|
||||||
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# test for _argcomplete but not specific for any application
|
# test for _argcomplete but not specific for any application
|
||||||
|
@ -23,21 +24,21 @@ def equal_with_bash(prefix, ffc, fc, out=None):
|
||||||
|
|
||||||
def _wrapcall(*args, **kargs):
|
def _wrapcall(*args, **kargs):
|
||||||
try:
|
try:
|
||||||
if py.std.sys.version_info > (2, 7):
|
if sys.version_info > (2, 7):
|
||||||
return py.std.subprocess.check_output(*args, **kargs).decode().splitlines()
|
return subprocess.check_output(*args, **kargs).decode().splitlines()
|
||||||
if 'stdout' in kargs:
|
if 'stdout' in kargs:
|
||||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||||
process = py.std.subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
stdout=py.std.subprocess.PIPE, *args, **kargs)
|
stdout=subprocess.PIPE, *args, **kargs)
|
||||||
output, unused_err = process.communicate()
|
output, unused_err = process.communicate()
|
||||||
retcode = process.poll()
|
retcode = process.poll()
|
||||||
if retcode:
|
if retcode:
|
||||||
cmd = kargs.get("args")
|
cmd = kargs.get("args")
|
||||||
if cmd is None:
|
if cmd is None:
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
raise py.std.subprocess.CalledProcessError(retcode, cmd)
|
raise subprocess.CalledProcessError(retcode, cmd)
|
||||||
return output.decode().splitlines()
|
return output.decode().splitlines()
|
||||||
except py.std.subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ class TestArgComplete(object):
|
||||||
ffc = FastFilesCompleter()
|
ffc = FastFilesCompleter()
|
||||||
fc = FilesCompleter()
|
fc = FilesCompleter()
|
||||||
for x in ['/', '/d', '/data', 'qqq', '']:
|
for x in ['/', '/d', '/data', 'qqq', '']:
|
||||||
assert equal_with_bash(x, ffc, fc, out=py.std.sys.stdout)
|
assert equal_with_bash(x, ffc, fc, out=sys.stdout)
|
||||||
|
|
||||||
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
|
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
|
||||||
def test_remove_dir_prefix(self):
|
def test_remove_dir_prefix(self):
|
||||||
|
@ -94,4 +95,4 @@ class TestArgComplete(object):
|
||||||
ffc = FastFilesCompleter()
|
ffc = FastFilesCompleter()
|
||||||
fc = FilesCompleter()
|
fc = FilesCompleter()
|
||||||
for x in '/usr/'.split():
|
for x in '/usr/'.split():
|
||||||
assert not equal_with_bash(x, ffc, fc, out=py.std.sys.stdout)
|
assert not equal_with_bash(x, ffc, fc, out=sys.stdout)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import py_compile
|
import py_compile
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
|
import textwrap
|
||||||
import zipfile
|
import zipfile
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -911,7 +912,7 @@ class TestAssertionRewriteHookDetails(object):
|
||||||
def test_reload_is_same(self, testdir):
|
def test_reload_is_same(self, testdir):
|
||||||
# A file that will be picked up during collecting.
|
# A file that will be picked up during collecting.
|
||||||
testdir.tmpdir.join("file.py").ensure()
|
testdir.tmpdir.join("file.py").ensure()
|
||||||
testdir.tmpdir.join("pytest.ini").write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join("pytest.ini").write(textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
python_files = *.py
|
python_files = *.py
|
||||||
"""))
|
"""))
|
||||||
|
@ -997,7 +998,7 @@ class TestIssue2121():
|
||||||
def test_simple_failure():
|
def test_simple_failure():
|
||||||
assert 1 + 1 == 3
|
assert 1 + 1 == 3
|
||||||
""")
|
""")
|
||||||
testdir.tmpdir.join("pytest.ini").write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join("pytest.ini").write(textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
python_files = tests/**.py
|
python_files = tests/**.py
|
||||||
"""))
|
"""))
|
||||||
|
|
|
@ -410,8 +410,8 @@ class TestLastFailed(object):
|
||||||
def test_lastfailed_collectfailure(self, testdir, monkeypatch):
|
def test_lastfailed_collectfailure(self, testdir, monkeypatch):
|
||||||
|
|
||||||
testdir.makepyfile(test_maybe="""
|
testdir.makepyfile(test_maybe="""
|
||||||
import py
|
import os
|
||||||
env = py.std.os.environ
|
env = os.environ
|
||||||
if '1' == env['FAILIMPORT']:
|
if '1' == env['FAILIMPORT']:
|
||||||
raise ImportError('fail')
|
raise ImportError('fail')
|
||||||
def test_hello():
|
def test_hello():
|
||||||
|
@ -439,8 +439,8 @@ class TestLastFailed(object):
|
||||||
def test_lastfailed_failure_subset(self, testdir, monkeypatch):
|
def test_lastfailed_failure_subset(self, testdir, monkeypatch):
|
||||||
|
|
||||||
testdir.makepyfile(test_maybe="""
|
testdir.makepyfile(test_maybe="""
|
||||||
import py
|
import os
|
||||||
env = py.std.os.environ
|
env = os.environ
|
||||||
if '1' == env['FAILIMPORT']:
|
if '1' == env['FAILIMPORT']:
|
||||||
raise ImportError('fail')
|
raise ImportError('fail')
|
||||||
def test_hello():
|
def test_hello():
|
||||||
|
@ -448,8 +448,8 @@ class TestLastFailed(object):
|
||||||
""")
|
""")
|
||||||
|
|
||||||
testdir.makepyfile(test_maybe2="""
|
testdir.makepyfile(test_maybe2="""
|
||||||
import py
|
import os
|
||||||
env = py.std.os.environ
|
env = os.environ
|
||||||
if '1' == env['FAILIMPORT']:
|
if '1' == env['FAILIMPORT']:
|
||||||
raise ImportError('fail')
|
raise ImportError('fail')
|
||||||
def test_hello():
|
def test_hello():
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
import py
|
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
from _pytest.main import Session, EXIT_NOTESTSCOLLECTED, _in_venv
|
from _pytest.main import Session, EXIT_NOTESTSCOLLECTED, _in_venv
|
||||||
|
@ -36,7 +37,7 @@ class TestCollector(object):
|
||||||
|
|
||||||
assert fn1 == fn2
|
assert fn1 == fn2
|
||||||
assert fn1 != modcol
|
assert fn1 != modcol
|
||||||
if py.std.sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
assert cmp(fn1, fn2) == 0
|
assert cmp(fn1, fn2) == 0
|
||||||
assert hash(fn1) == hash(fn2)
|
assert hash(fn1) == hash(fn2)
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ class TestCollectFS(object):
|
||||||
("activate", "activate.csh", "activate.fish",
|
("activate", "activate.csh", "activate.fish",
|
||||||
"Activate", "Activate.bat", "Activate.ps1"))
|
"Activate", "Activate.bat", "Activate.ps1"))
|
||||||
def test_ignored_virtualenvs(self, testdir, fname):
|
def test_ignored_virtualenvs(self, testdir, fname):
|
||||||
bindir = "Scripts" if py.std.sys.platform.startswith("win") else "bin"
|
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
||||||
testdir.tmpdir.ensure("virtual", bindir, fname)
|
testdir.tmpdir.ensure("virtual", bindir, fname)
|
||||||
testfile = testdir.tmpdir.ensure("virtual", "test_invenv.py")
|
testfile = testdir.tmpdir.ensure("virtual", "test_invenv.py")
|
||||||
testfile.write("def test_hello(): pass")
|
testfile.write("def test_hello(): pass")
|
||||||
|
@ -147,7 +148,7 @@ class TestCollectFS(object):
|
||||||
("activate", "activate.csh", "activate.fish",
|
("activate", "activate.csh", "activate.fish",
|
||||||
"Activate", "Activate.bat", "Activate.ps1"))
|
"Activate", "Activate.bat", "Activate.ps1"))
|
||||||
def test_ignored_virtualenvs_norecursedirs_precedence(self, testdir, fname):
|
def test_ignored_virtualenvs_norecursedirs_precedence(self, testdir, fname):
|
||||||
bindir = "Scripts" if py.std.sys.platform.startswith("win") else "bin"
|
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
||||||
# norecursedirs takes priority
|
# norecursedirs takes priority
|
||||||
testdir.tmpdir.ensure(".virtual", bindir, fname)
|
testdir.tmpdir.ensure(".virtual", bindir, fname)
|
||||||
testfile = testdir.tmpdir.ensure(".virtual", "test_invenv.py")
|
testfile = testdir.tmpdir.ensure(".virtual", "test_invenv.py")
|
||||||
|
@ -163,7 +164,7 @@ class TestCollectFS(object):
|
||||||
"Activate", "Activate.bat", "Activate.ps1"))
|
"Activate", "Activate.bat", "Activate.ps1"))
|
||||||
def test__in_venv(self, testdir, fname):
|
def test__in_venv(self, testdir, fname):
|
||||||
"""Directly test the virtual env detection function"""
|
"""Directly test the virtual env detection function"""
|
||||||
bindir = "Scripts" if py.std.sys.platform.startswith("win") else "bin"
|
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
||||||
# no bin/activate, not a virtualenv
|
# no bin/activate, not a virtualenv
|
||||||
base_path = testdir.tmpdir.mkdir('venv')
|
base_path = testdir.tmpdir.mkdir('venv')
|
||||||
assert _in_venv(base_path) is False
|
assert _in_venv(base_path) is False
|
||||||
|
@ -436,7 +437,7 @@ class TestSession(object):
|
||||||
assert item.name == "test_func"
|
assert item.name == "test_func"
|
||||||
newid = item.nodeid
|
newid = item.nodeid
|
||||||
assert newid == id
|
assert newid == id
|
||||||
py.std.pprint.pprint(hookrec.calls)
|
pprint.pprint(hookrec.calls)
|
||||||
topdir = testdir.tmpdir # noqa
|
topdir = testdir.tmpdir # noqa
|
||||||
hookrec.assert_contains([
|
hookrec.assert_contains([
|
||||||
("pytest_collectstart", "collector.fspath == topdir"),
|
("pytest_collectstart", "collector.fspath == topdir"),
|
||||||
|
@ -486,7 +487,7 @@ class TestSession(object):
|
||||||
id = p.basename
|
id = p.basename
|
||||||
|
|
||||||
items, hookrec = testdir.inline_genitems(id)
|
items, hookrec = testdir.inline_genitems(id)
|
||||||
py.std.pprint.pprint(hookrec.calls)
|
pprint.pprint(hookrec.calls)
|
||||||
assert len(items) == 2
|
assert len(items) == 2
|
||||||
hookrec.assert_contains([
|
hookrec.assert_contains([
|
||||||
("pytest_collectstart",
|
("pytest_collectstart",
|
||||||
|
@ -508,7 +509,7 @@ class TestSession(object):
|
||||||
|
|
||||||
items, hookrec = testdir.inline_genitems()
|
items, hookrec = testdir.inline_genitems()
|
||||||
assert len(items) == 1
|
assert len(items) == 1
|
||||||
py.std.pprint.pprint(hookrec.calls)
|
pprint.pprint(hookrec.calls)
|
||||||
hookrec.assert_contains([
|
hookrec.assert_contains([
|
||||||
("pytest_collectstart", "collector.fspath == test_aaa"),
|
("pytest_collectstart", "collector.fspath == test_aaa"),
|
||||||
("pytest_pycollect_makeitem", "name == 'test_func'"),
|
("pytest_pycollect_makeitem", "name == 'test_func'"),
|
||||||
|
@ -529,7 +530,7 @@ class TestSession(object):
|
||||||
|
|
||||||
items, hookrec = testdir.inline_genitems(id)
|
items, hookrec = testdir.inline_genitems(id)
|
||||||
assert len(items) == 2
|
assert len(items) == 2
|
||||||
py.std.pprint.pprint(hookrec.calls)
|
pprint.pprint(hookrec.calls)
|
||||||
hookrec.assert_contains([
|
hookrec.assert_contains([
|
||||||
("pytest_collectstart", "collector.fspath == test_aaa"),
|
("pytest_collectstart", "collector.fspath == test_aaa"),
|
||||||
("pytest_pycollect_makeitem", "name == 'test_func'"),
|
("pytest_pycollect_makeitem", "name == 'test_func'"),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import sys
|
import sys
|
||||||
import py
|
import textwrap
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
@ -57,7 +57,7 @@ class TestParseIni(object):
|
||||||
('pytest', 'pytest.ini')],
|
('pytest', 'pytest.ini')],
|
||||||
)
|
)
|
||||||
def test_ini_names(self, testdir, name, section):
|
def test_ini_names(self, testdir, name, section):
|
||||||
testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join(name).write(textwrap.dedent("""
|
||||||
[{section}]
|
[{section}]
|
||||||
minversion = 1.0
|
minversion = 1.0
|
||||||
""".format(section=section)))
|
""".format(section=section)))
|
||||||
|
@ -66,11 +66,11 @@ class TestParseIni(object):
|
||||||
|
|
||||||
def test_toxini_before_lower_pytestini(self, testdir):
|
def test_toxini_before_lower_pytestini(self, testdir):
|
||||||
sub = testdir.tmpdir.mkdir("sub")
|
sub = testdir.tmpdir.mkdir("sub")
|
||||||
sub.join("tox.ini").write(py.std.textwrap.dedent("""
|
sub.join("tox.ini").write(textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
minversion = 2.0
|
minversion = 2.0
|
||||||
"""))
|
"""))
|
||||||
testdir.tmpdir.join("pytest.ini").write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join("pytest.ini").write(textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
minversion = 1.5
|
minversion = 1.5
|
||||||
"""))
|
"""))
|
||||||
|
@ -731,7 +731,7 @@ class TestRootdir(object):
|
||||||
class TestOverrideIniArgs(object):
|
class TestOverrideIniArgs(object):
|
||||||
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
||||||
def test_override_ini_names(self, testdir, name):
|
def test_override_ini_names(self, testdir, name):
|
||||||
testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""
|
testdir.tmpdir.join(name).write(textwrap.dedent("""
|
||||||
[pytest]
|
[pytest]
|
||||||
custom = 1.0"""))
|
custom = 1.0"""))
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
|
|
|
@ -232,7 +232,7 @@ def test_fixture_dependency(testdir, monkeypatch):
|
||||||
ct1.write("")
|
ct1.write("")
|
||||||
sub = testdir.mkdir("sub")
|
sub = testdir.mkdir("sub")
|
||||||
sub.join("__init__.py").write("")
|
sub.join("__init__.py").write("")
|
||||||
sub.join("conftest.py").write(py.std.textwrap.dedent("""
|
sub.join("conftest.py").write(dedent("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -249,7 +249,7 @@ def test_fixture_dependency(testdir, monkeypatch):
|
||||||
"""))
|
"""))
|
||||||
subsub = sub.mkdir("subsub")
|
subsub = sub.mkdir("subsub")
|
||||||
subsub.join("__init__.py").write("")
|
subsub.join("__init__.py").write("")
|
||||||
subsub.join("test_bar.py").write(py.std.textwrap.dedent("""
|
subsub.join("test_bar.py").write(dedent("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -265,7 +265,7 @@ def test_fixture_dependency(testdir, monkeypatch):
|
||||||
|
|
||||||
def test_conftest_found_with_double_dash(testdir):
|
def test_conftest_found_with_double_dash(testdir):
|
||||||
sub = testdir.mkdir("sub")
|
sub = testdir.mkdir("sub")
|
||||||
sub.join("conftest.py").write(py.std.textwrap.dedent("""
|
sub.join("conftest.py").write(dedent("""
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption("--hello-world", action="store_true")
|
parser.addoption("--hello-world", action="store_true")
|
||||||
"""))
|
"""))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import py
|
import py
|
||||||
|
@ -189,7 +190,7 @@ class TestParser(object):
|
||||||
assert option.no is False
|
assert option.no is False
|
||||||
|
|
||||||
def test_drop_short_helper(self):
|
def test_drop_short_helper(self):
|
||||||
parser = py.std.argparse.ArgumentParser(formatter_class=parseopt.DropShorterLongHelpFormatter)
|
parser = argparse.ArgumentParser(formatter_class=parseopt.DropShorterLongHelpFormatter)
|
||||||
parser.add_argument('-t', '--twoword', '--duo', '--two-word', '--two',
|
parser.add_argument('-t', '--twoword', '--duo', '--two-word', '--two',
|
||||||
help='foo').map_long_option = {'two': 'two-word'}
|
help='foo').map_long_option = {'two': 'two-word'}
|
||||||
# throws error on --deux only!
|
# throws error on --deux only!
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import pytest
|
import pytest
|
||||||
import py
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import types
|
||||||
|
|
||||||
from _pytest.config import get_config, PytestPluginManager
|
from _pytest.config import get_config, PytestPluginManager
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED, Session
|
from _pytest.main import EXIT_NOTESTSCOLLECTED, Session
|
||||||
|
@ -208,14 +210,14 @@ def test_importplugin_error_message(testdir, pytestpm):
|
||||||
|
|
||||||
expected_message = '.*Error importing plugin "qwe": Not possible to import: .'
|
expected_message = '.*Error importing plugin "qwe": Not possible to import: .'
|
||||||
expected_traceback = ".*in test_traceback"
|
expected_traceback = ".*in test_traceback"
|
||||||
assert py.std.re.match(expected_message, str(excinfo.value))
|
assert re.match(expected_message, str(excinfo.value))
|
||||||
assert py.std.re.match(expected_traceback, str(excinfo.traceback[-1]))
|
assert re.match(expected_traceback, str(excinfo.traceback[-1]))
|
||||||
|
|
||||||
|
|
||||||
class TestPytestPluginManager(object):
|
class TestPytestPluginManager(object):
|
||||||
def test_register_imported_modules(self):
|
def test_register_imported_modules(self):
|
||||||
pm = PytestPluginManager()
|
pm = PytestPluginManager()
|
||||||
mod = py.std.types.ModuleType("x.y.pytest_hello")
|
mod = types.ModuleType("x.y.pytest_hello")
|
||||||
pm.register(mod)
|
pm.register(mod)
|
||||||
assert pm.is_registered(mod)
|
assert pm.is_registered(mod)
|
||||||
values = pm.get_plugins()
|
values = pm.get_plugins()
|
||||||
|
@ -226,8 +228,8 @@ class TestPytestPluginManager(object):
|
||||||
assert pm.get_plugins() == values
|
assert pm.get_plugins() == values
|
||||||
|
|
||||||
def test_canonical_import(self, monkeypatch):
|
def test_canonical_import(self, monkeypatch):
|
||||||
mod = py.std.types.ModuleType("pytest_xyz")
|
mod = types.ModuleType("pytest_xyz")
|
||||||
monkeypatch.setitem(py.std.sys.modules, 'pytest_xyz', mod)
|
monkeypatch.setitem(sys.modules, 'pytest_xyz', mod)
|
||||||
pm = PytestPluginManager()
|
pm = PytestPluginManager()
|
||||||
pm.import_plugin('pytest_xyz')
|
pm.import_plugin('pytest_xyz')
|
||||||
assert pm.get_plugin('pytest_xyz') == mod
|
assert pm.get_plugin('pytest_xyz') == mod
|
||||||
|
@ -237,7 +239,7 @@ class TestPytestPluginManager(object):
|
||||||
testdir.syspathinsert()
|
testdir.syspathinsert()
|
||||||
testdir.makepyfile(pytest_p1="#")
|
testdir.makepyfile(pytest_p1="#")
|
||||||
testdir.makepyfile(pytest_p2="#")
|
testdir.makepyfile(pytest_p2="#")
|
||||||
mod = py.std.types.ModuleType("temp")
|
mod = types.ModuleType("temp")
|
||||||
mod.pytest_plugins = ["pytest_p1", "pytest_p2"]
|
mod.pytest_plugins = ["pytest_p1", "pytest_p2"]
|
||||||
pytestpm.consider_module(mod)
|
pytestpm.consider_module(mod)
|
||||||
assert pytestpm.get_plugin("pytest_p1").__name__ == "pytest_p1"
|
assert pytestpm.get_plugin("pytest_p1").__name__ == "pytest_p1"
|
||||||
|
@ -245,12 +247,12 @@ class TestPytestPluginManager(object):
|
||||||
|
|
||||||
def test_consider_module_import_module(self, testdir):
|
def test_consider_module_import_module(self, testdir):
|
||||||
pytestpm = get_config().pluginmanager
|
pytestpm = get_config().pluginmanager
|
||||||
mod = py.std.types.ModuleType("x")
|
mod = types.ModuleType("x")
|
||||||
mod.pytest_plugins = "pytest_a"
|
mod.pytest_plugins = "pytest_a"
|
||||||
aplugin = testdir.makepyfile(pytest_a="#")
|
aplugin = testdir.makepyfile(pytest_a="#")
|
||||||
reprec = testdir.make_hook_recorder(pytestpm)
|
reprec = testdir.make_hook_recorder(pytestpm)
|
||||||
# syspath.prepend(aplugin.dirpath())
|
# syspath.prepend(aplugin.dirpath())
|
||||||
py.std.sys.path.insert(0, str(aplugin.dirpath()))
|
sys.path.insert(0, str(aplugin.dirpath()))
|
||||||
pytestpm.consider_module(mod)
|
pytestpm.consider_module(mod)
|
||||||
call = reprec.getcall(pytestpm.hook.pytest_plugin_registered.name)
|
call = reprec.getcall(pytestpm.hook.pytest_plugin_registered.name)
|
||||||
assert call.plugin.__name__ == "pytest_a"
|
assert call.plugin.__name__ == "pytest_a"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
import py
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.recwarn import WarningsRecorder
|
from _pytest.recwarn import WarningsRecorder
|
||||||
|
@ -24,9 +23,9 @@ class TestWarningsRecorderChecker(object):
|
||||||
rec = WarningsRecorder()
|
rec = WarningsRecorder()
|
||||||
with rec:
|
with rec:
|
||||||
assert not rec.list
|
assert not rec.list
|
||||||
py.std.warnings.warn_explicit("hello", UserWarning, "xyz", 13)
|
warnings.warn_explicit("hello", UserWarning, "xyz", 13)
|
||||||
assert len(rec.list) == 1
|
assert len(rec.list) == 1
|
||||||
py.std.warnings.warn(DeprecationWarning("hello"))
|
warnings.warn(DeprecationWarning("hello"))
|
||||||
assert len(rec.list) == 2
|
assert len(rec.list) == 2
|
||||||
warn = rec.pop()
|
warn = rec.pop()
|
||||||
assert str(warn.message) == "hello"
|
assert str(warn.message) == "hello"
|
||||||
|
@ -64,14 +63,14 @@ class TestDeprecatedCall(object):
|
||||||
|
|
||||||
def dep(self, i, j=None):
|
def dep(self, i, j=None):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
py.std.warnings.warn("is deprecated", DeprecationWarning,
|
warnings.warn("is deprecated", DeprecationWarning,
|
||||||
stacklevel=1)
|
stacklevel=1)
|
||||||
return 42
|
return 42
|
||||||
|
|
||||||
def dep_explicit(self, i):
|
def dep_explicit(self, i):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
py.std.warnings.warn_explicit("dep_explicit", category=DeprecationWarning,
|
warnings.warn_explicit("dep_explicit", category=DeprecationWarning,
|
||||||
filename="hello", lineno=3)
|
filename="hello", lineno=3)
|
||||||
|
|
||||||
def test_deprecated_call_raises(self):
|
def test_deprecated_call_raises(self):
|
||||||
with pytest.raises(AssertionError) as excinfo:
|
with pytest.raises(AssertionError) as excinfo:
|
||||||
|
@ -86,16 +85,16 @@ class TestDeprecatedCall(object):
|
||||||
assert ret == 42
|
assert ret == 42
|
||||||
|
|
||||||
def test_deprecated_call_preserves(self):
|
def test_deprecated_call_preserves(self):
|
||||||
onceregistry = py.std.warnings.onceregistry.copy()
|
onceregistry = warnings.onceregistry.copy()
|
||||||
filters = py.std.warnings.filters[:]
|
filters = warnings.filters[:]
|
||||||
warn = py.std.warnings.warn
|
warn = warnings.warn
|
||||||
warn_explicit = py.std.warnings.warn_explicit
|
warn_explicit = warnings.warn_explicit
|
||||||
self.test_deprecated_call_raises()
|
self.test_deprecated_call_raises()
|
||||||
self.test_deprecated_call()
|
self.test_deprecated_call()
|
||||||
assert onceregistry == py.std.warnings.onceregistry
|
assert onceregistry == warnings.onceregistry
|
||||||
assert filters == py.std.warnings.filters
|
assert filters == warnings.filters
|
||||||
assert warn is py.std.warnings.warn
|
assert warn is warnings.warn
|
||||||
assert warn_explicit is py.std.warnings.warn_explicit
|
assert warn_explicit is warnings.warn_explicit
|
||||||
|
|
||||||
def test_deprecated_explicit_call_raises(self):
|
def test_deprecated_explicit_call_raises(self):
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
from _pytest import runner, main, outcomes
|
from _pytest import runner, main, outcomes
|
||||||
|
|
||||||
|
|
||||||
|
@ -392,10 +394,10 @@ reporttypes = [
|
||||||
|
|
||||||
@pytest.mark.parametrize('reporttype', reporttypes, ids=[x.__name__ for x in reporttypes])
|
@pytest.mark.parametrize('reporttype', reporttypes, ids=[x.__name__ for x in reporttypes])
|
||||||
def test_report_extra_parameters(reporttype):
|
def test_report_extra_parameters(reporttype):
|
||||||
if hasattr(py.std.inspect, 'signature'):
|
if hasattr(inspect, 'signature'):
|
||||||
args = list(py.std.inspect.signature(reporttype.__init__).parameters.keys())[1:]
|
args = list(inspect.signature(reporttype.__init__).parameters.keys())[1:]
|
||||||
else:
|
else:
|
||||||
args = py.std.inspect.getargspec(reporttype.__init__)[0][1:]
|
args = inspect.getargspec(reporttype.__init__)[0][1:]
|
||||||
basekw = dict.fromkeys(args, [])
|
basekw = dict.fromkeys(args, [])
|
||||||
report = reporttype(newthing=1, **basekw)
|
report = reporttype(newthing=1, **basekw)
|
||||||
assert report.newthing == 1
|
assert report.newthing == 1
|
||||||
|
@ -564,10 +566,10 @@ def test_importorskip(monkeypatch):
|
||||||
importorskip("asdlkj")
|
importorskip("asdlkj")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sys = importorskip("sys")
|
sysmod = importorskip("sys")
|
||||||
assert sys == py.std.sys
|
assert sysmod is sys
|
||||||
# path = pytest.importorskip("os.path")
|
# path = pytest.importorskip("os.path")
|
||||||
# assert path == py.std.os.path
|
# assert path == os.path
|
||||||
excinfo = pytest.raises(pytest.skip.Exception, f)
|
excinfo = pytest.raises(pytest.skip.Exception, f)
|
||||||
path = py.path.local(excinfo.getrepr().reprcrash.path)
|
path = py.path.local(excinfo.getrepr().reprcrash.path)
|
||||||
# check that importorskip reports the actual call
|
# check that importorskip reports the actual call
|
||||||
|
@ -575,7 +577,7 @@ def test_importorskip(monkeypatch):
|
||||||
assert path.purebasename == "test_runner"
|
assert path.purebasename == "test_runner"
|
||||||
pytest.raises(SyntaxError, "pytest.importorskip('x y z')")
|
pytest.raises(SyntaxError, "pytest.importorskip('x y z')")
|
||||||
pytest.raises(SyntaxError, "pytest.importorskip('x=y')")
|
pytest.raises(SyntaxError, "pytest.importorskip('x=y')")
|
||||||
mod = py.std.types.ModuleType("hello123")
|
mod = types.ModuleType("hello123")
|
||||||
mod.__version__ = "1.3"
|
mod.__version__ = "1.3"
|
||||||
monkeypatch.setitem(sys.modules, "hello123", mod)
|
monkeypatch.setitem(sys.modules, "hello123", mod)
|
||||||
pytest.raises(pytest.skip.Exception, """
|
pytest.raises(pytest.skip.Exception, """
|
||||||
|
@ -595,7 +597,7 @@ def test_importorskip_imports_last_module_part():
|
||||||
|
|
||||||
def test_importorskip_dev_module(monkeypatch):
|
def test_importorskip_dev_module(monkeypatch):
|
||||||
try:
|
try:
|
||||||
mod = py.std.types.ModuleType("mockmodule")
|
mod = types.ModuleType("mockmodule")
|
||||||
mod.__version__ = '0.13.0.dev-43290'
|
mod.__version__ = '0.13.0.dev-43290'
|
||||||
monkeypatch.setitem(sys.modules, 'mockmodule', mod)
|
monkeypatch.setitem(sys.modules, 'mockmodule', mod)
|
||||||
mod2 = pytest.importorskip('mockmodule', minversion='0.12.0')
|
mod2 = pytest.importorskip('mockmodule', minversion='0.12.0')
|
||||||
|
|
|
@ -326,7 +326,7 @@ def test_repr_python_version(monkeypatch):
|
||||||
try:
|
try:
|
||||||
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
|
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
|
||||||
assert repr_pythonversion() == "2.5.1-final-0"
|
assert repr_pythonversion() == "2.5.1-final-0"
|
||||||
py.std.sys.version_info = x = (2, 3)
|
sys.version_info = x = (2, 3)
|
||||||
assert repr_pythonversion() == str(x)
|
assert repr_pythonversion() == str(x)
|
||||||
finally:
|
finally:
|
||||||
monkeypatch.undo() # do this early as pytest can get confused
|
monkeypatch.undo() # do this early as pytest can get confused
|
||||||
|
@ -475,11 +475,11 @@ class TestTerminalFunctional(object):
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
|
verinfo = ".".join(map(str, sys.version_info[:3]))
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*===== test session starts ====*",
|
"*===== test session starts ====*",
|
||||||
"platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s" % (
|
"platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s" % (
|
||||||
py.std.sys.platform, verinfo,
|
sys.platform, verinfo,
|
||||||
pytest.__version__, py.__version__, pluggy.__version__),
|
pytest.__version__, py.__version__, pluggy.__version__),
|
||||||
"*test_header_trailer_info.py .*",
|
"*test_header_trailer_info.py .*",
|
||||||
"=* 1 passed*in *.[0-9][0-9] seconds *=",
|
"=* 1 passed*in *.[0-9][0-9] seconds *=",
|
||||||
|
|
Loading…
Reference in New Issue