internally use pytest.* instead of ``py.test.*`` in many places.

make sub namespace names 'collect' and 'cmdline' available on pytest directly
This commit is contained in:
holger krekel 2010-11-13 09:05:11 +01:00
parent 323dd8a25a
commit 2e4e9eb745
23 changed files with 175 additions and 156 deletions

View File

@ -6,14 +6,14 @@ def pytest_collect_file(path, parent):
if path.ext == ".yml" and path.basename.startswith("test"): if path.ext == ".yml" and path.basename.startswith("test"):
return YamlFile(path, parent) return YamlFile(path, parent)
class YamlFile(py.test.collect.File): class YamlFile(pytest.File):
def collect(self): def collect(self):
import yaml # we need a yaml parser, e.g. PyYAML import yaml # we need a yaml parser, e.g. PyYAML
raw = yaml.load(self.fspath.open()) raw = yaml.load(self.fspath.open())
for name, spec in raw.items(): for name, spec in raw.items():
yield YamlItem(name, self, spec) yield YamlItem(name, self, spec)
class YamlItem(py.test.collect.Item): class YamlItem(pytest.Item):
def __init__(self, name, parent, spec): def __init__(self, name, parent, spec):
super(YamlItem, self).__init__(name, parent) super(YamlItem, self).__init__(name, parent)
self.spec = spec self.spec = spec

View File

@ -234,7 +234,7 @@ initialisation, command line and configuration hooks
generic "runtest" hooks generic "runtest" hooks
------------------------------ ------------------------------
All all runtest related hooks receive a :py:class:`pytest.collect.Item` object. All all runtest related hooks receive a :py:class:`pytest.Item` object.
.. autofunction:: pytest_runtest_protocol .. autofunction:: pytest_runtest_protocol
.. autofunction:: pytest_runtest_setup .. autofunction:: pytest_runtest_setup

View File

@ -60,7 +60,7 @@ modules to determine collectors and items at ``Directory``, ``Module``,
Customizing execution of Items and Functions Customizing execution of Items and Functions
---------------------------------------------------- ----------------------------------------------------
- ``py.test.collect.Function`` test items control execution - ``pytest.Function`` test items control execution
of a test function through its ``function.runtest()`` method. of a test function through its ``function.runtest()`` method.
This method is responsible for performing setup and teardown This method is responsible for performing setup and teardown
("Test Fixtures") for a test Function. ("Test Fixtures") for a test Function.

View File

@ -2,9 +2,9 @@ import py
mydir = py.path.local(__file__).dirpath() mydir = py.path.local(__file__).dirpath()
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
if isinstance(item, py.test.collect.Function): if isinstance(item, pytest.Function):
if not item.fspath.relto(mydir): if not item.fspath.relto(mydir):
return return
mod = item.getparent(py.test.collect.Module).obj mod = item.getparent(pytest.Module).obj
if hasattr(mod, 'hello'): if hasattr(mod, 'hello'):
py.builtin.print_("mod.hello", mod.hello) py.builtin.print_("mod.hello", mod.hello)

View File

@ -5,10 +5,10 @@ see http://pytest.org for documentation and details
(c) Holger Krekel and others, 2004-2010 (c) Holger Krekel and others, 2004-2010
""" """
__version__ = '2.0.0.dev24' __version__ = '2.0.0.dev25'
__all__ = ['config', 'cmdline'] __all__ = ['cmdline', 'collect', 'main']
from pytest import main as cmdline from pytest import main as cmdline
UsageError = cmdline.UsageError UsageError = cmdline.UsageError
main = cmdline.main main = cmdline.main

View File

@ -140,7 +140,7 @@ def pytest_runtest_teardown(item):
def pytest_runtest_makereport(item, call): def pytest_runtest_makereport(item, call):
""" return a :py:class:`pytest.plugin.runner.TestReport` object """ return a :py:class:`pytest.plugin.runner.TestReport` object
for the given :py:class:`pytest.collect.Item` and for the given :py:class:`pytest.Item` and
:py:class:`pytest.plugin.runner.CallInfo`. :py:class:`pytest.plugin.runner.CallInfo`.
""" """
pytest_runtest_makereport.firstresult = True pytest_runtest_makereport.firstresult = True

View File

@ -6,6 +6,7 @@ All else is in pytest/plugin.
import sys, os import sys, os
import inspect import inspect
import py import py
import pytest
from pytest import hookspec # the extension point definitions from pytest import hookspec # the extension point definitions
assert py.__version__.split(".")[:2] >= ['2', '0'], ("installation problem: " assert py.__version__.split(".")[:2] >= ['2', '0'], ("installation problem: "
@ -207,7 +208,7 @@ class PluginManager(object):
def pytest_plugin_registered(self, plugin): def pytest_plugin_registered(self, plugin):
dic = self.call_plugin(plugin, "pytest_namespace", {}) or {} dic = self.call_plugin(plugin, "pytest_namespace", {}) or {}
if dic: if dic:
self._setns(py.test, dic) self._setns(pytest, dic)
if hasattr(self, '_config'): if hasattr(self, '_config'):
self.call_plugin(plugin, "pytest_addoption", self.call_plugin(plugin, "pytest_addoption",
{'parser': self._config._parser}) {'parser': self._config._parser})
@ -219,16 +220,20 @@ class PluginManager(object):
if isinstance(value, dict): if isinstance(value, dict):
mod = getattr(obj, name, None) mod = getattr(obj, name, None)
if mod is None: if mod is None:
mod = py.std.types.ModuleType(name) modname = "pytest.%s" % name
sys.modules['pytest.%s' % name] = mod mod = py.std.types.ModuleType(modname)
sys.modules['py.test.%s' % name] = mod sys.modules[modname] = mod
mod.__all__ = [] mod.__all__ = []
setattr(obj, name, mod) setattr(obj, name, mod)
#print "setns", mod, value
self._setns(mod, value) self._setns(mod, value)
else: else:
#print "setting", name, value, "on", obj #print "setting", name, value, "on", obj
setattr(obj, name, value) setattr(obj, name, value)
obj.__all__.append(name) obj.__all__.append(name)
#print "appending", name, "to", obj
#pytest.__all__.append(name) # don't show in help(py.test)
setattr(pytest, name, value)
def pytest_terminal_summary(self, terminalreporter): def pytest_terminal_summary(self, terminalreporter):
tw = terminalreporter._tw tw = terminalreporter._tw
@ -284,6 +289,7 @@ def canonical_importname(name):
return name return name
def importplugin(importspec): def importplugin(importspec):
#print "importing", importspec
try: try:
return __import__(importspec, None, None, '__doc__') return __import__(importspec, None, None, '__doc__')
except ImportError: except ImportError:
@ -408,6 +414,9 @@ class HookCaller:
_preinit = [PluginManager(load=True)] # triggers default plugin importing _preinit = [PluginManager(load=True)] # triggers default plugin importing
def main(args=None, plugins=None): def main(args=None, plugins=None):
""" returned exit code integer, after an in-process testing run
with the given command line arguments, preloading an optional list
of passed in plugin objects. """
if args is None: if args is None:
args = sys.argv[1:] args = sys.argv[1:]
elif isinstance(args, py.path.local): elif isinstance(args, py.path.local):

View File

@ -1,6 +1,6 @@
""" discover and run doctests in modules and test files.""" """ discover and run doctests in modules and test files."""
import py import pytest, py
from py._code.code import TerminalRepr, ReprFileLocation from py._code.code import TerminalRepr, ReprFileLocation
def pytest_addoption(parser): def pytest_addoption(parser):
@ -31,7 +31,7 @@ class ReprFailDoctest(TerminalRepr):
tw.line(line) tw.line(line)
self.reprlocation.toterminal(tw) self.reprlocation.toterminal(tw)
class DoctestItem(py.test.collect.Item): class DoctestItem(pytest.Item):
def __init__(self, path, parent): def __init__(self, path, parent):
name = self.__class__.__name__ + ":" + path.basename name = self.__class__.__name__ + ":" + path.basename
super(DoctestItem, self).__init__(name=name, parent=parent) super(DoctestItem, self).__init__(name=name, parent=parent)

View File

@ -1,5 +1,5 @@
""" generic mechanism for marking and selecting python functions. """ """ generic mechanism for marking and selecting python functions. """
import py import pytest, py
def pytest_namespace(): def pytest_namespace():
return {'mark': MarkGenerator()} return {'mark': MarkGenerator()}
@ -156,13 +156,13 @@ class MarkInfo:
self._name, self.args, self.kwargs) self._name, self.args, self.kwargs)
def pytest_itemcollected(item): def pytest_itemcollected(item):
if not isinstance(item, py.test.collect.Function): if not isinstance(item, pytest.Function):
return return
try: try:
func = item.obj.__func__ func = item.obj.__func__
except AttributeError: except AttributeError:
func = getattr(item.obj, 'im_func', item.obj) func = getattr(item.obj, 'im_func', item.obj)
pyclasses = (py.test.collect.Class, py.test.collect.Module) pyclasses = (pytest.Class, pytest.Module)
for node in item.listchain(): for node in item.listchain():
if isinstance(node, pyclasses): if isinstance(node, pyclasses):
marker = getattr(node.obj, 'pytestmark', None) marker = getattr(node.obj, 'pytestmark', None)

View File

@ -1,6 +1,6 @@
"""run test suites written for nose. """ """run test suites written for nose. """
import py import pytest, py
import inspect import inspect
import sys import sys
@ -14,12 +14,12 @@ def pytest_runtest_makereport(__multicall__, item, call):
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
if isinstance(item, (py.test.collect.Function)): if isinstance(item, (pytest.Function)):
if isinstance(item.parent, py.test.collect.Generator): if isinstance(item.parent, pytest.Generator):
gen = item.parent gen = item.parent
if not hasattr(gen, '_nosegensetup'): if not hasattr(gen, '_nosegensetup'):
call_optional(gen.obj, 'setup') call_optional(gen.obj, 'setup')
if isinstance(gen.parent, py.test.collect.Instance): if isinstance(gen.parent, pytest.Instance):
call_optional(gen.parent.obj, 'setup') call_optional(gen.parent.obj, 'setup')
gen._nosegensetup = True gen._nosegensetup = True
if not call_optional(item.obj, 'setup'): if not call_optional(item.obj, 'setup'):
@ -27,7 +27,7 @@ def pytest_runtest_setup(item):
call_optional(item.parent.obj, 'setup') call_optional(item.parent.obj, 'setup')
def pytest_runtest_teardown(item): def pytest_runtest_teardown(item):
if isinstance(item, py.test.collect.Function): if isinstance(item, pytest.Function):
if not call_optional(item.obj, 'teardown'): if not call_optional(item.obj, 'teardown'):
call_optional(item.parent.obj, 'teardown') call_optional(item.parent.obj, 'teardown')
#if hasattr(item.parent, '_nosegensetup'): #if hasattr(item.parent, '_nosegensetup'):
@ -35,7 +35,7 @@ def pytest_runtest_teardown(item):
# del item.parent._nosegensetup # del item.parent._nosegensetup
def pytest_make_collect_report(collector): def pytest_make_collect_report(collector):
if isinstance(collector, py.test.collect.Generator): if isinstance(collector, pytest.Generator):
call_optional(collector.obj, 'setup') call_optional(collector.obj, 'setup')
def call_optional(obj, name): def call_optional(obj, name):

View File

@ -142,7 +142,7 @@ class PyobjMixin(object):
modpath = self.getmodpath() modpath = self.getmodpath()
return fspath, lineno, modpath return fspath, lineno, modpath
class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): class PyCollectorMixin(PyobjMixin, pytest.Collector):
def funcnamefilter(self, name): def funcnamefilter(self, name):
return name.startswith('test') return name.startswith('test')
@ -203,7 +203,7 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
l.append(function) l.append(function)
return l return l
class Module(pytest.collect.File, PyCollectorMixin): class Module(pytest.File, PyCollectorMixin):
def _getobj(self): def _getobj(self):
return self._memoizedcall('_obj', self._importtestmodule) return self._memoizedcall('_obj', self._importtestmodule)
@ -249,7 +249,7 @@ class Module(pytest.collect.File, PyCollectorMixin):
else: else:
self.obj.teardown_module() self.obj.teardown_module()
class Class(PyCollectorMixin, pytest.collect.Collector): class Class(PyCollectorMixin, pytest.Collector):
def collect(self): def collect(self):
return [Instance(name="()", parent=self)] return [Instance(name="()", parent=self)]
@ -266,7 +266,7 @@ class Class(PyCollectorMixin, pytest.collect.Collector):
teardown_class = getattr(teardown_class, 'im_func', teardown_class) teardown_class = getattr(teardown_class, 'im_func', teardown_class)
teardown_class(self.obj) teardown_class(self.obj)
class Instance(PyCollectorMixin, pytest.collect.Collector): class Instance(PyCollectorMixin, pytest.Collector):
def _getobj(self): def _getobj(self):
return self.parent.obj() return self.parent.obj()
@ -348,7 +348,7 @@ class FuncargLookupErrorRepr(TerminalRepr):
tw.line() tw.line()
tw.line("%s:%d" % (self.filename, self.firstlineno+1)) tw.line("%s:%d" % (self.filename, self.firstlineno+1))
class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector): class Generator(FunctionMixin, PyCollectorMixin, pytest.Collector):
def collect(self): def collect(self):
# test generators are seen as collectors but they also # test generators are seen as collectors but they also
# invoke setup/teardown on popular request # invoke setup/teardown on popular request
@ -388,7 +388,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector):
# Test Items # Test Items
# #
_dummy = object() _dummy = object()
class Function(FunctionMixin, pytest.collect.Item): class Function(FunctionMixin, pytest.Item):
""" a Function Item is responsible for setting up """ a Function Item is responsible for setting up
and executing a Python callable test object. and executing a Python callable test object.
""" """
@ -480,10 +480,10 @@ def fillfuncargs(function):
def getplugins(node, withpy=False): # might by any node def getplugins(node, withpy=False): # might by any node
plugins = node.config._getmatchingplugins(node.fspath) plugins = node.config._getmatchingplugins(node.fspath)
if withpy: if withpy:
mod = node.getparent(pytest.collect.Module) mod = node.getparent(pytest.Module)
if mod is not None: if mod is not None:
plugins.append(mod.obj) plugins.append(mod.obj)
inst = node.getparent(pytest.collect.Instance) inst = node.getparent(pytest.Instance)
if inst is not None: if inst is not None:
plugins.append(inst.obj) plugins.append(inst.obj)
return plugins return plugins
@ -573,12 +573,12 @@ class FuncargRequest:
@property @property
def module(self): def module(self):
""" module where the test function was collected. """ """ module where the test function was collected. """
return self._pyfuncitem.getparent(pytest.collect.Module).obj return self._pyfuncitem.getparent(pytest.Module).obj
@property @property
def cls(self): def cls(self):
""" class (can be None) where the test function was collected. """ """ class (can be None) where the test function was collected. """
clscol = self._pyfuncitem.getparent(pytest.collect.Class) clscol = self._pyfuncitem.getparent(pytest.Class)
if clscol: if clscol:
return clscol.obj return clscol.obj
@property @property
@ -679,7 +679,7 @@ class FuncargRequest:
if scope == "function": if scope == "function":
return self._pyfuncitem return self._pyfuncitem
elif scope == "module": elif scope == "module":
return self._pyfuncitem.getparent(py.test.collect.Module) return self._pyfuncitem.getparent(pytest.Module)
elif scope == "session": elif scope == "session":
return None return None
raise ValueError("unknown finalization scope %r" %(scope,)) raise ValueError("unknown finalization scope %r" %(scope,))

View File

@ -122,9 +122,9 @@ class HookProxy:
def compatproperty(name): def compatproperty(name):
def fget(self): def fget(self):
#print "retrieving %r property from %s" %(name, self.fspath) #print "retrieving %r property from %s" %(name, self.fspath)
py.log._apiwarn("2.0", "use py.test.collect.%s for " py.log._apiwarn("2.0", "use pytest.%s for "
"Session classes" % name) "test collection and item classes" % name)
return getattr(pytest.collect, name) return getattr(pytest, name)
return property(fget) return property(fget)
class Node(object): class Node(object):
@ -479,10 +479,10 @@ class Session(FSCollector):
nextnames = names[1:] nextnames = names[1:]
resultnodes = [] resultnodes = []
for node in matching: for node in matching:
if isinstance(node, pytest.collect.Item): if isinstance(node, pytest.Item):
resultnodes.append(node) resultnodes.append(node)
continue continue
assert isinstance(node, pytest.collect.Collector) assert isinstance(node, pytest.Collector)
node.ihook.pytest_collectstart(collector=node) node.ihook.pytest_collectstart(collector=node)
rep = node.ihook.pytest_make_collect_report(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node)
if rep.passed: if rep.passed:
@ -494,11 +494,11 @@ class Session(FSCollector):
def genitems(self, node): def genitems(self, node):
self.trace("genitems", node) self.trace("genitems", node)
if isinstance(node, pytest.collect.Item): if isinstance(node, pytest.Item):
node.ihook.pytest_itemcollected(item=node) node.ihook.pytest_itemcollected(item=node)
yield node yield node
else: else:
assert isinstance(node, pytest.collect.Collector) assert isinstance(node, pytest.Collector)
node.ihook.pytest_collectstart(collector=node) node.ihook.pytest_collectstart(collector=node)
rep = node.ihook.pytest_make_collect_report(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node)
if rep.passed: if rep.passed:

View File

@ -65,7 +65,7 @@ class MarkEvaluator:
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
if not isinstance(item, py.test.collect.Function): if not isinstance(item, pytest.Function):
return return
evalskip = MarkEvaluator(item, 'skipif') evalskip = MarkEvaluator(item, 'skipif')
if evalskip.istrue(): if evalskip.istrue():
@ -84,7 +84,7 @@ def check_xfail_no_run(item):
py.test.xfail("[NOTRUN] " + evalxfail.getexplanation()) py.test.xfail("[NOTRUN] " + evalxfail.getexplanation())
def pytest_runtest_makereport(__multicall__, item, call): def pytest_runtest_makereport(__multicall__, item, call):
if not isinstance(item, py.test.collect.Function): if not isinstance(item, pytest.Function):
return return
if not (call.excinfo and if not (call.excinfo and
call.excinfo.errisinstance(py.test.xfail.Exception)): call.excinfo.errisinstance(py.test.xfail.Exception)):

View File

@ -1,5 +1,5 @@
""" discovery and running of std-library "unittest" style tests. """ """ discovery and running of std-library "unittest" style tests. """
import py import pytest, py
import sys import sys
def pytest_pycollect_makeitem(collector, name, obj): def pytest_pycollect_makeitem(collector, name, obj):
@ -16,7 +16,7 @@ def pytest_pycollect_makeitem(collector, name, obj):
if isunit: if isunit:
return UnitTestCase(name, parent=collector) return UnitTestCase(name, parent=collector)
class UnitTestCase(py.test.collect.Class): class UnitTestCase(pytest.Class):
def collect(self): def collect(self):
loader = py.std.unittest.TestLoader() loader = py.std.unittest.TestLoader()
for name in loader.getTestCaseNames(self.obj): for name in loader.getTestCaseNames(self.obj):
@ -32,7 +32,7 @@ class UnitTestCase(py.test.collect.Class):
if meth is not None: if meth is not None:
meth() meth()
class TestCaseFunction(py.test.collect.Function): class TestCaseFunction(pytest.Function):
def setup(self): def setup(self):
pass pass
def teardown(self): def teardown(self):

View File

@ -22,7 +22,7 @@ def main():
name='pytest', name='pytest',
description='py.test: simple powerful testing with Python', description='py.test: simple powerful testing with Python',
long_description = long_description, long_description = long_description,
version='2.0.0.dev24', version='2.0.0.dev25',
url='http://pytest.org', url='http://pytest.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -24,7 +24,6 @@ class TestGeneralUsage:
parser.addoption("--xyz", dest="xyz", action="store") parser.addoption("--xyz", dest="xyz", action="store")
""") """)
testdir.makepyfile(test_one=""" testdir.makepyfile(test_one="""
import py
def test_option(pytestconfig): def test_option(pytestconfig):
assert pytestconfig.option.xyz == "123" assert pytestconfig.option.xyz == "123"
""") """)
@ -37,7 +36,6 @@ class TestGeneralUsage:
def test_basetemp(self, testdir): def test_basetemp(self, testdir):
mytemp = testdir.tmpdir.mkdir("mytemp") mytemp = testdir.tmpdir.mkdir("mytemp")
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import py
def test_1(pytestconfig): def test_1(pytestconfig):
pytestconfig.getbasetemp().ensure("hello") pytestconfig.getbasetemp().ensure("hello")
""") """)
@ -86,9 +84,9 @@ class TestGeneralUsage:
def test_early_skip(self, testdir): def test_early_skip(self, testdir):
testdir.mkdir("xyz") testdir.mkdir("xyz")
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_collect_directory(): def pytest_collect_directory():
py.test.skip("early") pytest.skip("early")
""") """)
result = testdir.runpytest() result = testdir.runpytest()
assert result.ret == 0 assert result.ret == 0
@ -98,8 +96,8 @@ class TestGeneralUsage:
def test_issue88_initial_file_multinodes(self, testdir): def test_issue88_initial_file_multinodes(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
class MyFile(py.test.collect.File): class MyFile(pytest.File):
def collect(self): def collect(self):
return return
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
@ -163,9 +161,9 @@ class TestGeneralUsage:
def test_directory_skipped(self, testdir): def test_directory_skipped(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_ignore_collect(): def pytest_ignore_collect():
py.test.skip("intentional") pytest.skip("intentional")
""") """)
testdir.makepyfile("def test_hello(): pass") testdir.makepyfile("def test_hello(): pass")
result = testdir.runpytest() result = testdir.runpytest()
@ -176,11 +174,11 @@ class TestGeneralUsage:
def test_multiple_items_per_collector_byid(self, testdir): def test_multiple_items_per_collector_byid(self, testdir):
c = testdir.makeconftest(""" c = testdir.makeconftest("""
import py import pytest
class MyItem(py.test.collect.Item): class MyItem(pytest.Item):
def runtest(self): def runtest(self):
pass pass
class MyCollector(py.test.collect.File): class MyCollector(pytest.File):
def collect(self): def collect(self):
return [MyItem(name="xyz", parent=self)] return [MyItem(name="xyz", parent=self)]
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
@ -195,13 +193,13 @@ class TestGeneralUsage:
def test_skip_on_generated_funcarg_id(self, testdir): def test_skip_on_generated_funcarg_id(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
metafunc.addcall({'x': 3}, id='hello-123') metafunc.addcall({'x': 3}, id='hello-123')
def pytest_runtest_setup(item): def pytest_runtest_setup(item):
print (item.keywords) print (item.keywords)
if 'hello-123' in item.keywords: if 'hello-123' in item.keywords:
py.test.skip("hello") pytest.skip("hello")
assert 0 assert 0
""") """)
p = testdir.makepyfile("""def test_func(x): pass""") p = testdir.makepyfile("""def test_func(x): pass""")
@ -233,23 +231,37 @@ class TestGeneralUsage:
class TestInvocationVariants: class TestInvocationVariants:
def test_earlyinit(self, testdir): def test_earlyinit(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import py import pytest
assert hasattr(py.test, 'mark') assert hasattr(pytest, 'mark')
""") """)
result = testdir.runpython(p) result = testdir.runpython(p)
assert result.ret == 0 assert result.ret == 0
def test_pydoc(self, testdir): def test_pydoc(self, testdir):
result = testdir.runpython_c("import py;help(py.test)") for name in ('py.test', 'pytest'):
result = testdir.runpython_c("import %s;help(%s)" % (name,name))
assert result.ret == 0
s = result.stdout.str()
assert 'MarkGenerator' in s
@pytest.mark.multi(source=['py.test', 'pytest'])
def test_import_star(self, testdir, source):
p = testdir.makepyfile("""
from %s import *
collect
cmdline
main
skip
xfail
""" % source)
result = testdir.runpython(p)
assert result.ret == 0 assert result.ret == 0
s = result.stdout.str()
assert 'MarkGenerator' in s
def test_double_pytestcmdline(self, testdir): def test_double_pytestcmdline(self, testdir):
p = testdir.makepyfile(run=""" p = testdir.makepyfile(run="""
import py import py, pytest
py.test.cmdline.main() pytest.main()
py.test.cmdline.main() pytest.main()
""") """)
testdir.makepyfile(""" testdir.makepyfile("""
def test_hello(): def test_hello():
@ -343,7 +355,6 @@ class TestInvocationVariants:
def test_noclass_discovery_if_not_testcase(self, testdir): def test_noclass_discovery_if_not_testcase(self, testdir):
testpath = testdir.makepyfile(""" testpath = testdir.makepyfile("""
import unittest import unittest
import py
class TestHello(object): class TestHello(object):
def test_hello(self): def test_hello(self):
assert self.attr assert self.attr

View File

@ -237,11 +237,11 @@ class TestPython:
class TestNonPython: class TestNonPython:
def test_summing_simple(self, testdir): def test_summing_simple(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".xyz": if path.ext == ".xyz":
return MyItem(path, parent) return MyItem(path, parent)
class MyItem(py.test.collect.Item): class MyItem(pytest.Item):
def __init__(self, path, parent): def __init__(self, path, parent):
super(MyItem, self).__init__(path.basename, parent) super(MyItem, self).__init__(path.basename, parent)
self.fspath = path self.fspath = path

View File

@ -59,11 +59,11 @@ class TestGenerator:
colitems = modcol.collect() colitems = modcol.collect()
assert len(colitems) == 1 assert len(colitems) == 1
gencol = colitems[0] gencol = colitems[0]
assert isinstance(gencol, py.test.collect.Generator) assert isinstance(gencol, pytest.Generator)
gencolitems = gencol.collect() gencolitems = gencol.collect()
assert len(gencolitems) == 2 assert len(gencolitems) == 2
assert isinstance(gencolitems[0], py.test.collect.Function) assert isinstance(gencolitems[0], pytest.Function)
assert isinstance(gencolitems[1], py.test.collect.Function) assert isinstance(gencolitems[1], pytest.Function)
assert gencolitems[0].name == '[0]' assert gencolitems[0].name == '[0]'
assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[0].obj.__name__ == 'func1'
@ -77,11 +77,11 @@ class TestGenerator:
yield func1, 42, 6*7 yield func1, 42, 6*7
""") """)
gencol = modcol.collect()[0].collect()[0].collect()[0] gencol = modcol.collect()[0].collect()[0].collect()[0]
assert isinstance(gencol, py.test.collect.Generator) assert isinstance(gencol, pytest.Generator)
gencolitems = gencol.collect() gencolitems = gencol.collect()
assert len(gencolitems) == 2 assert len(gencolitems) == 2
assert isinstance(gencolitems[0], py.test.collect.Function) assert isinstance(gencolitems[0], pytest.Function)
assert isinstance(gencolitems[1], py.test.collect.Function) assert isinstance(gencolitems[1], pytest.Function)
assert gencolitems[0].name == '[0]' assert gencolitems[0].name == '[0]'
assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[0].obj.__name__ == 'func1'
@ -97,11 +97,11 @@ class TestGenerator:
colitems = modcol.collect() colitems = modcol.collect()
assert len(colitems) == 1 assert len(colitems) == 1
gencol = colitems[0] gencol = colitems[0]
assert isinstance(gencol, py.test.collect.Generator) assert isinstance(gencol, pytest.Generator)
gencolitems = gencol.collect() gencolitems = gencol.collect()
assert len(gencolitems) == 2 assert len(gencolitems) == 2
assert isinstance(gencolitems[0], py.test.collect.Function) assert isinstance(gencolitems[0], pytest.Function)
assert isinstance(gencolitems[1], py.test.collect.Function) assert isinstance(gencolitems[1], pytest.Function)
assert gencolitems[0].name == "['seventeen']" assert gencolitems[0].name == "['seventeen']"
assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[0].obj.__name__ == 'func1'
assert gencolitems[1].name == "['fortytwo']" assert gencolitems[1].name == "['fortytwo']"
@ -118,7 +118,7 @@ class TestGenerator:
colitems = modcol.collect() colitems = modcol.collect()
assert len(colitems) == 1 assert len(colitems) == 1
gencol = colitems[0] gencol = colitems[0]
assert isinstance(gencol, py.test.collect.Generator) assert isinstance(gencol, pytest.Generator)
py.test.raises(ValueError, "gencol.collect()") py.test.raises(ValueError, "gencol.collect()")
def test_generative_methods_with_explicit_names(self, testdir): def test_generative_methods_with_explicit_names(self, testdir):
@ -131,11 +131,11 @@ class TestGenerator:
yield "m2", func1, 42, 6*7 yield "m2", func1, 42, 6*7
""") """)
gencol = modcol.collect()[0].collect()[0].collect()[0] gencol = modcol.collect()[0].collect()[0].collect()[0]
assert isinstance(gencol, py.test.collect.Generator) assert isinstance(gencol, pytest.Generator)
gencolitems = gencol.collect() gencolitems = gencol.collect()
assert len(gencolitems) == 2 assert len(gencolitems) == 2
assert isinstance(gencolitems[0], py.test.collect.Function) assert isinstance(gencolitems[0], pytest.Function)
assert isinstance(gencolitems[1], py.test.collect.Function) assert isinstance(gencolitems[1], pytest.Function)
assert gencolitems[0].name == "['m1']" assert gencolitems[0].name == "['m1']"
assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[0].obj.__name__ == 'func1'
assert gencolitems[1].name == "['m2']" assert gencolitems[1].name == "['m2']"
@ -199,20 +199,20 @@ class TestGenerator:
class TestFunction: class TestFunction:
def test_getmodulecollector(self, testdir): def test_getmodulecollector(self, testdir):
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
modcol = item.getparent(py.test.collect.Module) modcol = item.getparent(pytest.Module)
assert isinstance(modcol, py.test.collect.Module) assert isinstance(modcol, pytest.Module)
assert hasattr(modcol.obj, 'test_func') assert hasattr(modcol.obj, 'test_func')
def test_function_equality(self, testdir, tmpdir): def test_function_equality(self, testdir, tmpdir):
config = testdir.reparseconfig() config = testdir.reparseconfig()
session = testdir.Session(config) session = testdir.Session(config)
f1 = py.test.collect.Function(name="name", config=config, f1 = pytest.Function(name="name", config=config,
args=(1,), callobj=isinstance, session=session) args=(1,), callobj=isinstance, session=session)
f2 = py.test.collect.Function(name="name",config=config, f2 = pytest.Function(name="name",config=config,
args=(1,), callobj=py.builtin.callable, session=session) args=(1,), callobj=py.builtin.callable, session=session)
assert not f1 == f2 assert not f1 == f2
assert f1 != f2 assert f1 != f2
f3 = py.test.collect.Function(name="name", config=config, f3 = pytest.Function(name="name", config=config,
args=(1,2), callobj=py.builtin.callable, session=session) args=(1,2), callobj=py.builtin.callable, session=session)
assert not f3 == f2 assert not f3 == f2
assert f3 != f2 assert f3 != f2
@ -220,7 +220,7 @@ class TestFunction:
assert not f3 == f1 assert not f3 == f1
assert f3 != f1 assert f3 != f1
f1_b = py.test.collect.Function(name="name", config=config, f1_b = pytest.Function(name="name", config=config,
args=(1,), callobj=isinstance, session=session) args=(1,), callobj=isinstance, session=session)
assert f1 == f1_b assert f1 == f1_b
assert not f1 != f1_b assert not f1 != f1_b
@ -236,9 +236,9 @@ class TestFunction:
funcargs = {} funcargs = {}
id = "world" id = "world"
session = testdir.Session(config) session = testdir.Session(config)
f5 = py.test.collect.Function(name="name", config=config, f5 = pytest.Function(name="name", config=config,
callspec=callspec1, callobj=isinstance, session=session) callspec=callspec1, callobj=isinstance, session=session)
f5b = py.test.collect.Function(name="name", config=config, f5b = pytest.Function(name="name", config=config,
callspec=callspec2, callobj=isinstance, session=session) callspec=callspec2, callobj=isinstance, session=session)
assert f5 != f5b assert f5 != f5b
assert not (f5 == f5b) assert not (f5 == f5b)
@ -263,9 +263,9 @@ class TestSorting:
def test_fail(): assert 0 def test_fail(): assert 0
""") """)
fn1 = testdir.collect_by_name(modcol, "test_pass") fn1 = testdir.collect_by_name(modcol, "test_pass")
assert isinstance(fn1, py.test.collect.Function) assert isinstance(fn1, pytest.Function)
fn2 = testdir.collect_by_name(modcol, "test_pass") fn2 = testdir.collect_by_name(modcol, "test_pass")
assert isinstance(fn2, py.test.collect.Function) assert isinstance(fn2, pytest.Function)
assert fn1 == fn2 assert fn1 == fn2
assert fn1 != modcol assert fn1 != modcol
@ -274,7 +274,7 @@ class TestSorting:
assert hash(fn1) == hash(fn2) assert hash(fn1) == hash(fn2)
fn3 = testdir.collect_by_name(modcol, "test_fail") fn3 = testdir.collect_by_name(modcol, "test_fail")
assert isinstance(fn3, py.test.collect.Function) assert isinstance(fn3, pytest.Function)
assert not (fn1 == fn3) assert not (fn1 == fn3)
assert fn1 != fn3 assert fn1 != fn3
@ -309,8 +309,8 @@ class TestSorting:
class TestConftestCustomization: class TestConftestCustomization:
def test_pytest_pycollect_module(self, testdir): def test_pytest_pycollect_module(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
class MyModule(py.test.collect.Module): class MyModule(pytest.Module):
pass pass
def pytest_pycollect_makemodule(path, parent): def pytest_pycollect_makemodule(path, parent):
if path.basename == "test_xyz.py": if path.basename == "test_xyz.py":
@ -326,8 +326,8 @@ class TestConftestCustomization:
def test_pytest_pycollect_makeitem(self, testdir): def test_pytest_pycollect_makeitem(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
class MyFunction(py.test.collect.Function): class MyFunction(pytest.Function):
pass pass
def pytest_pycollect_makeitem(collector, name, obj): def pytest_pycollect_makeitem(collector, name, obj):
if name == "some": if name == "some":
@ -342,7 +342,7 @@ class TestConftestCustomization:
def test_makeitem_non_underscore(self, testdir, monkeypatch): def test_makeitem_non_underscore(self, testdir, monkeypatch):
modcol = testdir.getmodulecol("def _hello(): pass") modcol = testdir.getmodulecol("def _hello(): pass")
l = [] l = []
monkeypatch.setattr(py.test.collect.Module, 'makeitem', monkeypatch.setattr(pytest.Module, 'makeitem',
lambda self, name, obj: l.append(name)) lambda self, name, obj: l.append(name))
l = modcol.collect() l = modcol.collect()
assert '_hello' not in l assert '_hello' not in l
@ -545,7 +545,7 @@ class TestFillFuncArgs:
item.config.pluginmanager.register(Provider()) item.config.pluginmanager.register(Provider())
if hasattr(item, '_args'): if hasattr(item, '_args'):
del item._args del item._args
py.test.collect._fillfuncargs(item) pytest._fillfuncargs(item)
assert len(item.funcargs) == 1 assert len(item.funcargs) == 1
class TestRequest: class TestRequest:
@ -634,7 +634,7 @@ class TestRequest:
req.config._setupstate.prepare(item) # XXX req.config._setupstate.prepare(item) # XXX
req._fillfuncargs() req._fillfuncargs()
# successively check finalization calls # successively check finalization calls
teardownlist = item.getparent(py.test.collect.Module).obj.teardownlist teardownlist = item.getparent(pytest.Module).obj.teardownlist
ss = item.config._setupstate ss = item.config._setupstate
assert not teardownlist assert not teardownlist
ss.teardown_exact(item) ss.teardown_exact(item)
@ -1009,11 +1009,11 @@ def test_conftest_funcargs_only_available_in_subdir(testdir):
def test_funcarg_non_pycollectobj(testdir): # rough jstests usage def test_funcarg_non_pycollectobj(testdir): # rough jstests usage
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_pycollect_makeitem(collector, name, obj): def pytest_pycollect_makeitem(collector, name, obj):
if name == "MyClass": if name == "MyClass":
return MyCollector(name, parent=collector) return MyCollector(name, parent=collector)
class MyCollector(py.test.collect.Collector): class MyCollector(pytest.Collector):
def reportinfo(self): def reportinfo(self):
return self.fspath, 3, "xyz" return self.fspath, 3, "xyz"
""") """)
@ -1048,8 +1048,8 @@ def test_funcarg_lookup_error(testdir):
class TestReportInfo: class TestReportInfo:
def test_itemreport_reportinfo(self, testdir, linecomp): def test_itemreport_reportinfo(self, testdir, linecomp):
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
class MyFunction(py.test.collect.Function): class MyFunction(pytest.Function):
def reportinfo(self): def reportinfo(self):
return "ABCDE", 42, "custom" return "ABCDE", 42, "custom"
def pytest_pycollect_makeitem(collector, name, obj): def pytest_pycollect_makeitem(collector, name, obj):

View File

@ -141,8 +141,8 @@ class BaseFunctionalTests:
def test_custom_failure_repr(self, testdir): def test_custom_failure_repr(self, testdir):
testdir.makepyfile(conftest=""" testdir.makepyfile(conftest="""
import py import pytest
class Function(py.test.collect.Function): class Function(pytest.Function):
def repr_failure(self, excinfo): def repr_failure(self, excinfo):
return "hello" return "hello"
""") """)
@ -162,13 +162,12 @@ class BaseFunctionalTests:
def test_failure_in_setup_function_ignores_custom_repr(self, testdir): def test_failure_in_setup_function_ignores_custom_repr(self, testdir):
testdir.makepyfile(conftest=""" testdir.makepyfile(conftest="""
import py import pytest
class Function(py.test.collect.Function): class Function(pytest.Function):
def repr_failure(self, excinfo): def repr_failure(self, excinfo):
assert 0 assert 0
""") """)
reports = testdir.runitem(""" reports = testdir.runitem("""
import py
def setup_function(func): def setup_function(func):
raise ValueError(42) raise ValueError(42)
def test_func(): def test_func():
@ -200,9 +199,9 @@ class BaseFunctionalTests:
def test_exit_propagates(self, testdir): def test_exit_propagates(self, testdir):
try: try:
testdir.runitem(""" testdir.runitem("""
import py import pytest
def test_func(): def test_func():
raise py.test.exit.Exception() raise pytest.exit.Exception()
""") """)
except py.test.exit.Exception: except py.test.exit.Exception:
pass pass
@ -267,8 +266,8 @@ class TestSessionReports:
def test_skip_at_module_scope(self, testdir): def test_skip_at_module_scope(self, testdir):
col = testdir.getmodulecol(""" col = testdir.getmodulecol("""
import py import pytest
py.test.skip("hello") pytest.skip("hello")
def test_func(): def test_func():
pass pass
""") """)

View File

@ -1,4 +1,4 @@
import py import pytest, py
class SessionTests: class SessionTests:
def test_basic_testitem_events(self, testdir): def test_basic_testitem_events(self, testdir):
@ -26,7 +26,7 @@ class SessionTests:
colstarted = reprec.getcalls("pytest_collectstart") colstarted = reprec.getcalls("pytest_collectstart")
assert len(colstarted) == 1 + 1 assert len(colstarted) == 1 + 1
col = colstarted[1].collector col = colstarted[1].collector
assert isinstance(col, py.test.collect.Module) assert isinstance(col, pytest.Module)
def test_nested_import_error(self, testdir): def test_nested_import_error(self, testdir):
tfile = testdir.makepyfile(""" tfile = testdir.makepyfile("""
@ -94,7 +94,7 @@ class SessionTests:
def test_broken_repr(self, testdir): def test_broken_repr(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import py import pytest
class BrokenRepr1: class BrokenRepr1:
foo=0 foo=0
def __repr__(self): def __repr__(self):
@ -103,7 +103,7 @@ class SessionTests:
class TestBrokenClass: class TestBrokenClass:
def test_explicit_bad_repr(self): def test_explicit_bad_repr(self):
t = BrokenRepr1() t = BrokenRepr1()
py.test.raises(Exception, 'repr(t)') pytest.raises(Exception, 'repr(t)')
def test_implicit_bad_repr1(self): def test_implicit_bad_repr1(self):
t = BrokenRepr1() t = BrokenRepr1()

View File

@ -1,10 +1,10 @@
import py import pytest, py
from pytest.plugin.session import Session from pytest.plugin.session import Session
class TestCollector: class TestCollector:
def test_collect_versus_item(self): def test_collect_versus_item(self):
from pytest.collect import Collector, Item from pytest import Collector, Item
assert not issubclass(Collector, Item) assert not issubclass(Collector, Item)
assert not issubclass(Item, Collector) assert not issubclass(Item, Collector)
@ -14,15 +14,15 @@ class TestCollector:
def test_fail(): assert 0 def test_fail(): assert 0
""") """)
recwarn.clear() recwarn.clear()
assert modcol.Module == py.test.collect.Module assert modcol.Module == pytest.Module
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
assert modcol.Class == py.test.collect.Class assert modcol.Class == pytest.Class
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
assert modcol.Item == py.test.collect.Item assert modcol.Item == pytest.Item
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
assert modcol.File == py.test.collect.File assert modcol.File == pytest.File
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
assert modcol.Function == py.test.collect.Function assert modcol.Function == pytest.Function
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
def test_check_equality(self, testdir): def test_check_equality(self, testdir):
@ -31,9 +31,9 @@ class TestCollector:
def test_fail(): assert 0 def test_fail(): assert 0
""") """)
fn1 = testdir.collect_by_name(modcol, "test_pass") fn1 = testdir.collect_by_name(modcol, "test_pass")
assert isinstance(fn1, py.test.collect.Function) assert isinstance(fn1, pytest.Function)
fn2 = testdir.collect_by_name(modcol, "test_pass") fn2 = testdir.collect_by_name(modcol, "test_pass")
assert isinstance(fn2, py.test.collect.Function) assert isinstance(fn2, pytest.Function)
assert fn1 == fn2 assert fn1 == fn2
assert fn1 != modcol assert fn1 != modcol
@ -42,7 +42,7 @@ class TestCollector:
assert hash(fn1) == hash(fn2) assert hash(fn1) == hash(fn2)
fn3 = testdir.collect_by_name(modcol, "test_fail") fn3 = testdir.collect_by_name(modcol, "test_fail")
assert isinstance(fn3, py.test.collect.Function) assert isinstance(fn3, pytest.Function)
assert not (fn1 == fn3) assert not (fn1 == fn3)
assert fn1 != fn3 assert fn1 != fn3
@ -63,32 +63,32 @@ class TestCollector:
fn = testdir.collect_by_name( fn = testdir.collect_by_name(
testdir.collect_by_name(cls, "()"), "test_foo") testdir.collect_by_name(cls, "()"), "test_foo")
parent = fn.getparent(py.test.collect.Module) parent = fn.getparent(pytest.Module)
assert parent is modcol assert parent is modcol
parent = fn.getparent(py.test.collect.Function) parent = fn.getparent(pytest.Function)
assert parent is fn assert parent is fn
parent = fn.getparent(py.test.collect.Class) parent = fn.getparent(pytest.Class)
assert parent is cls assert parent is cls
def test_getcustomfile_roundtrip(self, testdir): def test_getcustomfile_roundtrip(self, testdir):
hello = testdir.makefile(".xxx", hello="world") hello = testdir.makefile(".xxx", hello="world")
testdir.makepyfile(conftest=""" testdir.makepyfile(conftest="""
import py import pytest
class CustomFile(py.test.collect.File): class CustomFile(pytest.File):
pass pass
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".xxx": if path.ext == ".xxx":
return CustomFile(path, parent=parent) return CustomFile(path, parent=parent)
""") """)
node = testdir.getpathnode(hello) node = testdir.getpathnode(hello)
assert isinstance(node, py.test.collect.File) assert isinstance(node, pytest.File)
assert node.name == "hello.xxx" assert node.name == "hello.xxx"
nodes = node.session.perform_collect([node.nodeid], genitems=False) nodes = node.session.perform_collect([node.nodeid], genitems=False)
assert len(nodes) == 1 assert len(nodes) == 1
assert isinstance(nodes[0], py.test.collect.File) assert isinstance(nodes[0], pytest.File)
class TestCollectFS: class TestCollectFS:
def test_ignored_certain_directories(self, testdir): def test_ignored_certain_directories(self, testdir):
@ -158,18 +158,18 @@ class TestPrunetraceback:
import not_exists import not_exists
""") """)
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
return MyFile(path, parent) return MyFile(path, parent)
class MyError(Exception): class MyError(Exception):
pass pass
class MyFile(py.test.collect.File): class MyFile(pytest.File):
def collect(self): def collect(self):
raise MyError() raise MyError()
def repr_failure(self, excinfo): def repr_failure(self, excinfo):
if excinfo.errisinstance(MyError): if excinfo.errisinstance(MyError):
return "hello world" return "hello world"
return py.test.collect.File.repr_failure(self, excinfo) return pytest.File.repr_failure(self, excinfo)
""") """)
result = testdir.runpytest(p) result = testdir.runpytest(p)
@ -184,7 +184,7 @@ class TestPrunetraceback:
import not_exists import not_exists
""") """)
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
def pytest_make_collect_report(__multicall__): def pytest_make_collect_report(__multicall__):
rep = __multicall__.execute() rep = __multicall__.execute()
rep.headerlines += ["header1"] rep.headerlines += ["header1"]
@ -246,8 +246,8 @@ class TestCustomConftests:
def test_pytest_fs_collect_hooks_are_seen(self, testdir): def test_pytest_fs_collect_hooks_are_seen(self, testdir):
conf = testdir.makeconftest(""" conf = testdir.makeconftest("""
import py import pytest
class MyModule(py.test.collect.Module): class MyModule(pytest.Module):
pass pass
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".py": if path.ext == ".py":
@ -265,8 +265,8 @@ class TestCustomConftests:
sub1 = testdir.mkpydir("sub1") sub1 = testdir.mkpydir("sub1")
sub2 = testdir.mkpydir("sub2") sub2 = testdir.mkpydir("sub2")
conf1 = testdir.makeconftest(""" conf1 = testdir.makeconftest("""
import py import pytest
class MyModule1(py.test.collect.Module): class MyModule1(pytest.Module):
pass pass
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".py": if path.ext == ".py":
@ -274,8 +274,8 @@ class TestCustomConftests:
""") """)
conf1.move(sub1.join(conf1.basename)) conf1.move(sub1.join(conf1.basename))
conf2 = testdir.makeconftest(""" conf2 = testdir.makeconftest("""
import py import pytest
class MyModule2(py.test.collect.Module): class MyModule2(pytest.Module):
pass pass
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".py": if path.ext == ".py":
@ -378,11 +378,11 @@ class TestSession:
def test_collect_custom_nodes_multi_id(self, testdir): def test_collect_custom_nodes_multi_id(self, testdir):
p = testdir.makepyfile("def test_func(): pass") p = testdir.makepyfile("def test_func(): pass")
testdir.makeconftest(""" testdir.makeconftest("""
import py import pytest
class SpecialItem(py.test.collect.Item): class SpecialItem(pytest.Item):
def runtest(self): def runtest(self):
return # ok return # ok
class SpecialFile(py.test.collect.File): class SpecialFile(pytest.File):
def collect(self): def collect(self):
return [SpecialItem(name="check", parent=self)] return [SpecialItem(name="check", parent=self)]
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
@ -481,7 +481,7 @@ class Test_getinitialnodes:
x = tmpdir.ensure("x.py") x = tmpdir.ensure("x.py")
config = testdir.reparseconfig([x]) config = testdir.reparseconfig([x])
col = testdir.getnode(config, x) col = testdir.getnode(config, x)
assert isinstance(col, py.test.collect.Module) assert isinstance(col, pytest.Module)
assert col.name == 'x.py' assert col.name == 'x.py'
assert col.parent.name == testdir.tmpdir.basename assert col.parent.name == testdir.tmpdir.basename
assert col.parent.parent is None assert col.parent.parent is None
@ -496,7 +496,7 @@ class Test_getinitialnodes:
subdir.ensure("__init__.py") subdir.ensure("__init__.py")
config = testdir.reparseconfig([x]) config = testdir.reparseconfig([x])
col = testdir.getnode(config, x) col = testdir.getnode(config, x)
assert isinstance(col, py.test.collect.Module) assert isinstance(col, pytest.Module)
assert col.name == 'subdir/x.py' assert col.name == 'subdir/x.py'
assert col.parent.parent is None assert col.parent.parent is None
for col in col.listchain(): for col in col.listchain():

View File

@ -52,7 +52,7 @@ class TestConftestValueAccessGlobal:
def test_default_has_lower_prio(self, basedir): def test_default_has_lower_prio(self, basedir):
conftest = ConftestWithSetinitial(basedir.join("adir")) conftest = ConftestWithSetinitial(basedir.join("adir"))
assert conftest.rget('Directory') == 3 assert conftest.rget('Directory') == 3
#assert conftest.lget('Directory') == py.test.collect.Directory #assert conftest.lget('Directory') == pytest.Directory
def test_value_access_not_existing(self, basedir): def test_value_access_not_existing(self, basedir):
conftest = ConftestWithSetinitial(basedir) conftest = ConftestWithSetinitial(basedir)

View File

@ -352,8 +352,8 @@ class TestPytestPluginInteractions:
def test_namespace_early_from_import(self, testdir): def test_namespace_early_from_import(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
from py.test.collect import Item from pytest import Item
from pytest.collect import Item as Item2 from pytest import Item as Item2
assert Item is Item2 assert Item is Item2
""") """)
result = testdir.runpython(p) result = testdir.runpython(p)