diff --git a/doc/example/nonpython/conftest.py b/doc/example/nonpython/conftest.py index e75b48da6..b665ec3cb 100644 --- a/doc/example/nonpython/conftest.py +++ b/doc/example/nonpython/conftest.py @@ -6,14 +6,14 @@ def pytest_collect_file(path, parent): if path.ext == ".yml" and path.basename.startswith("test"): return YamlFile(path, parent) -class YamlFile(py.test.collect.File): +class YamlFile(pytest.File): def collect(self): import yaml # we need a yaml parser, e.g. PyYAML raw = yaml.load(self.fspath.open()) for name, spec in raw.items(): yield YamlItem(name, self, spec) -class YamlItem(py.test.collect.Item): +class YamlItem(pytest.Item): def __init__(self, name, parent, spec): super(YamlItem, self).__init__(name, parent) self.spec = spec diff --git a/doc/plugins.txt b/doc/plugins.txt index fcc38d2d6..e62104546 100644 --- a/doc/plugins.txt +++ b/doc/plugins.txt @@ -234,7 +234,7 @@ initialisation, command line and configuration 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_setup diff --git a/doc/test/attic.txt b/doc/test/attic.txt index a1096c149..b90ab4be9 100644 --- a/doc/test/attic.txt +++ b/doc/test/attic.txt @@ -60,7 +60,7 @@ modules to determine collectors and items at ``Directory``, ``Module``, 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. This method is responsible for performing setup and teardown ("Test Fixtures") for a test Function. diff --git a/example/assertion/global_testmodule_config/conftest.py b/example/assertion/global_testmodule_config/conftest.py index ba31b335b..293cbea3c 100644 --- a/example/assertion/global_testmodule_config/conftest.py +++ b/example/assertion/global_testmodule_config/conftest.py @@ -2,9 +2,9 @@ import py mydir = py.path.local(__file__).dirpath() def pytest_runtest_setup(item): - if isinstance(item, py.test.collect.Function): + if isinstance(item, pytest.Function): if not item.fspath.relto(mydir): return - mod = item.getparent(py.test.collect.Module).obj + mod = item.getparent(pytest.Module).obj if hasattr(mod, 'hello'): py.builtin.print_("mod.hello", mod.hello) diff --git a/pytest/__init__.py b/pytest/__init__.py index 3e7212eaf..6942c3b52 100644 --- a/pytest/__init__.py +++ b/pytest/__init__.py @@ -5,10 +5,10 @@ see http://pytest.org for documentation and details (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 UsageError = cmdline.UsageError -main = cmdline.main \ No newline at end of file +main = cmdline.main diff --git a/pytest/hookspec.py b/pytest/hookspec.py index 674e6384a..ba06c479a 100644 --- a/pytest/hookspec.py +++ b/pytest/hookspec.py @@ -140,7 +140,7 @@ def pytest_runtest_teardown(item): def pytest_runtest_makereport(item, call): """ 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`. """ pytest_runtest_makereport.firstresult = True diff --git a/pytest/main.py b/pytest/main.py index 6a90bfbdf..dabf441ea 100644 --- a/pytest/main.py +++ b/pytest/main.py @@ -6,6 +6,7 @@ All else is in pytest/plugin. import sys, os import inspect import py +import pytest from pytest import hookspec # the extension point definitions assert py.__version__.split(".")[:2] >= ['2', '0'], ("installation problem: " @@ -207,7 +208,7 @@ class PluginManager(object): def pytest_plugin_registered(self, plugin): dic = self.call_plugin(plugin, "pytest_namespace", {}) or {} if dic: - self._setns(py.test, dic) + self._setns(pytest, dic) if hasattr(self, '_config'): self.call_plugin(plugin, "pytest_addoption", {'parser': self._config._parser}) @@ -219,16 +220,20 @@ class PluginManager(object): if isinstance(value, dict): mod = getattr(obj, name, None) if mod is None: - mod = py.std.types.ModuleType(name) - sys.modules['pytest.%s' % name] = mod - sys.modules['py.test.%s' % name] = mod + modname = "pytest.%s" % name + mod = py.std.types.ModuleType(modname) + sys.modules[modname] = mod mod.__all__ = [] setattr(obj, name, mod) + #print "setns", mod, value self._setns(mod, value) else: #print "setting", name, value, "on", obj setattr(obj, name, value) 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): tw = terminalreporter._tw @@ -284,6 +289,7 @@ def canonical_importname(name): return name def importplugin(importspec): + #print "importing", importspec try: return __import__(importspec, None, None, '__doc__') except ImportError: @@ -408,6 +414,9 @@ class HookCaller: _preinit = [PluginManager(load=True)] # triggers default plugin importing 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: args = sys.argv[1:] elif isinstance(args, py.path.local): diff --git a/pytest/plugin/doctest.py b/pytest/plugin/doctest.py index 092b55b75..e1ed3782c 100644 --- a/pytest/plugin/doctest.py +++ b/pytest/plugin/doctest.py @@ -1,6 +1,6 @@ """ discover and run doctests in modules and test files.""" -import py +import pytest, py from py._code.code import TerminalRepr, ReprFileLocation def pytest_addoption(parser): @@ -31,7 +31,7 @@ class ReprFailDoctest(TerminalRepr): tw.line(line) self.reprlocation.toterminal(tw) -class DoctestItem(py.test.collect.Item): +class DoctestItem(pytest.Item): def __init__(self, path, parent): name = self.__class__.__name__ + ":" + path.basename super(DoctestItem, self).__init__(name=name, parent=parent) diff --git a/pytest/plugin/mark.py b/pytest/plugin/mark.py index d9f40d59d..55ea0485b 100644 --- a/pytest/plugin/mark.py +++ b/pytest/plugin/mark.py @@ -1,5 +1,5 @@ """ generic mechanism for marking and selecting python functions. """ -import py +import pytest, py def pytest_namespace(): return {'mark': MarkGenerator()} @@ -156,13 +156,13 @@ class MarkInfo: self._name, self.args, self.kwargs) def pytest_itemcollected(item): - if not isinstance(item, py.test.collect.Function): + if not isinstance(item, pytest.Function): return try: func = item.obj.__func__ except AttributeError: 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(): if isinstance(node, pyclasses): marker = getattr(node.obj, 'pytestmark', None) diff --git a/pytest/plugin/nose.py b/pytest/plugin/nose.py index 69cfc6cf2..af07ae8f8 100644 --- a/pytest/plugin/nose.py +++ b/pytest/plugin/nose.py @@ -1,6 +1,6 @@ """run test suites written for nose. """ -import py +import pytest, py import inspect import sys @@ -14,12 +14,12 @@ def pytest_runtest_makereport(__multicall__, item, call): def pytest_runtest_setup(item): - if isinstance(item, (py.test.collect.Function)): - if isinstance(item.parent, py.test.collect.Generator): + if isinstance(item, (pytest.Function)): + if isinstance(item.parent, pytest.Generator): gen = item.parent if not hasattr(gen, '_nosegensetup'): 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') gen._nosegensetup = True if not call_optional(item.obj, 'setup'): @@ -27,7 +27,7 @@ def pytest_runtest_setup(item): call_optional(item.parent.obj, 'setup') def pytest_runtest_teardown(item): - if isinstance(item, py.test.collect.Function): + if isinstance(item, pytest.Function): if not call_optional(item.obj, 'teardown'): call_optional(item.parent.obj, 'teardown') #if hasattr(item.parent, '_nosegensetup'): @@ -35,7 +35,7 @@ def pytest_runtest_teardown(item): # del item.parent._nosegensetup def pytest_make_collect_report(collector): - if isinstance(collector, py.test.collect.Generator): + if isinstance(collector, pytest.Generator): call_optional(collector.obj, 'setup') def call_optional(obj, name): diff --git a/pytest/plugin/python.py b/pytest/plugin/python.py index c4472fa9d..3893f9726 100644 --- a/pytest/plugin/python.py +++ b/pytest/plugin/python.py @@ -142,7 +142,7 @@ class PyobjMixin(object): modpath = self.getmodpath() return fspath, lineno, modpath -class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): +class PyCollectorMixin(PyobjMixin, pytest.Collector): def funcnamefilter(self, name): return name.startswith('test') @@ -203,7 +203,7 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): l.append(function) return l -class Module(pytest.collect.File, PyCollectorMixin): +class Module(pytest.File, PyCollectorMixin): def _getobj(self): return self._memoizedcall('_obj', self._importtestmodule) @@ -249,7 +249,7 @@ class Module(pytest.collect.File, PyCollectorMixin): else: self.obj.teardown_module() -class Class(PyCollectorMixin, pytest.collect.Collector): +class Class(PyCollectorMixin, pytest.Collector): def collect(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(self.obj) -class Instance(PyCollectorMixin, pytest.collect.Collector): +class Instance(PyCollectorMixin, pytest.Collector): def _getobj(self): return self.parent.obj() @@ -348,7 +348,7 @@ class FuncargLookupErrorRepr(TerminalRepr): tw.line() 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): # test generators are seen as collectors but they also # invoke setup/teardown on popular request @@ -388,7 +388,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector): # Test Items # _dummy = object() -class Function(FunctionMixin, pytest.collect.Item): +class Function(FunctionMixin, pytest.Item): """ a Function Item is responsible for setting up and executing a Python callable test object. """ @@ -480,10 +480,10 @@ def fillfuncargs(function): def getplugins(node, withpy=False): # might by any node plugins = node.config._getmatchingplugins(node.fspath) if withpy: - mod = node.getparent(pytest.collect.Module) + mod = node.getparent(pytest.Module) if mod is not None: plugins.append(mod.obj) - inst = node.getparent(pytest.collect.Instance) + inst = node.getparent(pytest.Instance) if inst is not None: plugins.append(inst.obj) return plugins @@ -573,12 +573,12 @@ class FuncargRequest: @property def module(self): """ module where the test function was collected. """ - return self._pyfuncitem.getparent(pytest.collect.Module).obj + return self._pyfuncitem.getparent(pytest.Module).obj @property def cls(self): """ 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: return clscol.obj @property @@ -679,7 +679,7 @@ class FuncargRequest: if scope == "function": return self._pyfuncitem elif scope == "module": - return self._pyfuncitem.getparent(py.test.collect.Module) + return self._pyfuncitem.getparent(pytest.Module) elif scope == "session": return None raise ValueError("unknown finalization scope %r" %(scope,)) diff --git a/pytest/plugin/session.py b/pytest/plugin/session.py index b5624d5bf..69366ae80 100644 --- a/pytest/plugin/session.py +++ b/pytest/plugin/session.py @@ -122,9 +122,9 @@ class HookProxy: def compatproperty(name): def fget(self): #print "retrieving %r property from %s" %(name, self.fspath) - py.log._apiwarn("2.0", "use py.test.collect.%s for " - "Session classes" % name) - return getattr(pytest.collect, name) + py.log._apiwarn("2.0", "use pytest.%s for " + "test collection and item classes" % name) + return getattr(pytest, name) return property(fget) class Node(object): @@ -479,10 +479,10 @@ class Session(FSCollector): nextnames = names[1:] resultnodes = [] for node in matching: - if isinstance(node, pytest.collect.Item): + if isinstance(node, pytest.Item): resultnodes.append(node) continue - assert isinstance(node, pytest.collect.Collector) + assert isinstance(node, pytest.Collector) node.ihook.pytest_collectstart(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node) if rep.passed: @@ -494,11 +494,11 @@ class Session(FSCollector): def genitems(self, node): self.trace("genitems", node) - if isinstance(node, pytest.collect.Item): + if isinstance(node, pytest.Item): node.ihook.pytest_itemcollected(item=node) yield node else: - assert isinstance(node, pytest.collect.Collector) + assert isinstance(node, pytest.Collector) node.ihook.pytest_collectstart(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node) if rep.passed: diff --git a/pytest/plugin/skipping.py b/pytest/plugin/skipping.py index c8044109d..841406d87 100644 --- a/pytest/plugin/skipping.py +++ b/pytest/plugin/skipping.py @@ -65,7 +65,7 @@ class MarkEvaluator: def pytest_runtest_setup(item): - if not isinstance(item, py.test.collect.Function): + if not isinstance(item, pytest.Function): return evalskip = MarkEvaluator(item, 'skipif') if evalskip.istrue(): @@ -84,7 +84,7 @@ def check_xfail_no_run(item): py.test.xfail("[NOTRUN] " + evalxfail.getexplanation()) def pytest_runtest_makereport(__multicall__, item, call): - if not isinstance(item, py.test.collect.Function): + if not isinstance(item, pytest.Function): return if not (call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception)): diff --git a/pytest/plugin/unittest.py b/pytest/plugin/unittest.py index b903927c6..f61e03bb6 100644 --- a/pytest/plugin/unittest.py +++ b/pytest/plugin/unittest.py @@ -1,5 +1,5 @@ """ discovery and running of std-library "unittest" style tests. """ -import py +import pytest, py import sys def pytest_pycollect_makeitem(collector, name, obj): @@ -16,7 +16,7 @@ def pytest_pycollect_makeitem(collector, name, obj): if isunit: return UnitTestCase(name, parent=collector) -class UnitTestCase(py.test.collect.Class): +class UnitTestCase(pytest.Class): def collect(self): loader = py.std.unittest.TestLoader() for name in loader.getTestCaseNames(self.obj): @@ -32,7 +32,7 @@ class UnitTestCase(py.test.collect.Class): if meth is not None: meth() -class TestCaseFunction(py.test.collect.Function): +class TestCaseFunction(pytest.Function): def setup(self): pass def teardown(self): diff --git a/setup.py b/setup.py index 82c4a21b5..6fe75ea48 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.0.dev24', + version='2.0.0.dev25', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 9b06e0996..6b5d2c767 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -24,7 +24,6 @@ class TestGeneralUsage: parser.addoption("--xyz", dest="xyz", action="store") """) testdir.makepyfile(test_one=""" - import py def test_option(pytestconfig): assert pytestconfig.option.xyz == "123" """) @@ -37,7 +36,6 @@ class TestGeneralUsage: def test_basetemp(self, testdir): mytemp = testdir.tmpdir.mkdir("mytemp") p = testdir.makepyfile(""" - import py def test_1(pytestconfig): pytestconfig.getbasetemp().ensure("hello") """) @@ -86,9 +84,9 @@ class TestGeneralUsage: def test_early_skip(self, testdir): testdir.mkdir("xyz") testdir.makeconftest(""" - import py + import pytest def pytest_collect_directory(): - py.test.skip("early") + pytest.skip("early") """) result = testdir.runpytest() assert result.ret == 0 @@ -98,8 +96,8 @@ class TestGeneralUsage: def test_issue88_initial_file_multinodes(self, testdir): testdir.makeconftest(""" - import py - class MyFile(py.test.collect.File): + import pytest + class MyFile(pytest.File): def collect(self): return def pytest_collect_file(path, parent): @@ -163,9 +161,9 @@ class TestGeneralUsage: def test_directory_skipped(self, testdir): testdir.makeconftest(""" - import py + import pytest def pytest_ignore_collect(): - py.test.skip("intentional") + pytest.skip("intentional") """) testdir.makepyfile("def test_hello(): pass") result = testdir.runpytest() @@ -176,11 +174,11 @@ class TestGeneralUsage: def test_multiple_items_per_collector_byid(self, testdir): c = testdir.makeconftest(""" - import py - class MyItem(py.test.collect.Item): + import pytest + class MyItem(pytest.Item): def runtest(self): pass - class MyCollector(py.test.collect.File): + class MyCollector(pytest.File): def collect(self): return [MyItem(name="xyz", parent=self)] def pytest_collect_file(path, parent): @@ -195,13 +193,13 @@ class TestGeneralUsage: def test_skip_on_generated_funcarg_id(self, testdir): testdir.makeconftest(""" - import py + import pytest def pytest_generate_tests(metafunc): metafunc.addcall({'x': 3}, id='hello-123') def pytest_runtest_setup(item): print (item.keywords) if 'hello-123' in item.keywords: - py.test.skip("hello") + pytest.skip("hello") assert 0 """) p = testdir.makepyfile("""def test_func(x): pass""") @@ -233,23 +231,37 @@ class TestGeneralUsage: class TestInvocationVariants: def test_earlyinit(self, testdir): p = testdir.makepyfile(""" - import py - assert hasattr(py.test, 'mark') + import pytest + assert hasattr(pytest, 'mark') """) result = testdir.runpython(p) assert result.ret == 0 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 - s = result.stdout.str() - assert 'MarkGenerator' in s def test_double_pytestcmdline(self, testdir): p = testdir.makepyfile(run=""" - import py - py.test.cmdline.main() - py.test.cmdline.main() + import py, pytest + pytest.main() + pytest.main() """) testdir.makepyfile(""" def test_hello(): @@ -343,7 +355,6 @@ class TestInvocationVariants: def test_noclass_discovery_if_not_testcase(self, testdir): testpath = testdir.makepyfile(""" import unittest - import py class TestHello(object): def test_hello(self): assert self.attr diff --git a/testing/plugin/test_junitxml.py b/testing/plugin/test_junitxml.py index f1e5ed164..36def8dbd 100644 --- a/testing/plugin/test_junitxml.py +++ b/testing/plugin/test_junitxml.py @@ -237,11 +237,11 @@ class TestPython: class TestNonPython: def test_summing_simple(self, testdir): testdir.makeconftest(""" - import py + import pytest def pytest_collect_file(path, parent): if path.ext == ".xyz": return MyItem(path, parent) - class MyItem(py.test.collect.Item): + class MyItem(pytest.Item): def __init__(self, path, parent): super(MyItem, self).__init__(path.basename, parent) self.fspath = path diff --git a/testing/plugin/test_python.py b/testing/plugin/test_python.py index 57aadfe6f..4fe295516 100644 --- a/testing/plugin/test_python.py +++ b/testing/plugin/test_python.py @@ -59,11 +59,11 @@ class TestGenerator: colitems = modcol.collect() assert len(colitems) == 1 gencol = colitems[0] - assert isinstance(gencol, py.test.collect.Generator) + assert isinstance(gencol, pytest.Generator) gencolitems = gencol.collect() assert len(gencolitems) == 2 - assert isinstance(gencolitems[0], py.test.collect.Function) - assert isinstance(gencolitems[1], py.test.collect.Function) + assert isinstance(gencolitems[0], pytest.Function) + assert isinstance(gencolitems[1], pytest.Function) assert gencolitems[0].name == '[0]' assert gencolitems[0].obj.__name__ == 'func1' @@ -77,11 +77,11 @@ class TestGenerator: yield func1, 42, 6*7 """) gencol = modcol.collect()[0].collect()[0].collect()[0] - assert isinstance(gencol, py.test.collect.Generator) + assert isinstance(gencol, pytest.Generator) gencolitems = gencol.collect() assert len(gencolitems) == 2 - assert isinstance(gencolitems[0], py.test.collect.Function) - assert isinstance(gencolitems[1], py.test.collect.Function) + assert isinstance(gencolitems[0], pytest.Function) + assert isinstance(gencolitems[1], pytest.Function) assert gencolitems[0].name == '[0]' assert gencolitems[0].obj.__name__ == 'func1' @@ -97,11 +97,11 @@ class TestGenerator: colitems = modcol.collect() assert len(colitems) == 1 gencol = colitems[0] - assert isinstance(gencol, py.test.collect.Generator) + assert isinstance(gencol, pytest.Generator) gencolitems = gencol.collect() assert len(gencolitems) == 2 - assert isinstance(gencolitems[0], py.test.collect.Function) - assert isinstance(gencolitems[1], py.test.collect.Function) + assert isinstance(gencolitems[0], pytest.Function) + assert isinstance(gencolitems[1], pytest.Function) assert gencolitems[0].name == "['seventeen']" assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[1].name == "['fortytwo']" @@ -118,7 +118,7 @@ class TestGenerator: colitems = modcol.collect() assert len(colitems) == 1 gencol = colitems[0] - assert isinstance(gencol, py.test.collect.Generator) + assert isinstance(gencol, pytest.Generator) py.test.raises(ValueError, "gencol.collect()") def test_generative_methods_with_explicit_names(self, testdir): @@ -131,11 +131,11 @@ class TestGenerator: yield "m2", func1, 42, 6*7 """) gencol = modcol.collect()[0].collect()[0].collect()[0] - assert isinstance(gencol, py.test.collect.Generator) + assert isinstance(gencol, pytest.Generator) gencolitems = gencol.collect() assert len(gencolitems) == 2 - assert isinstance(gencolitems[0], py.test.collect.Function) - assert isinstance(gencolitems[1], py.test.collect.Function) + assert isinstance(gencolitems[0], pytest.Function) + assert isinstance(gencolitems[1], pytest.Function) assert gencolitems[0].name == "['m1']" assert gencolitems[0].obj.__name__ == 'func1' assert gencolitems[1].name == "['m2']" @@ -199,20 +199,20 @@ class TestGenerator: class TestFunction: def test_getmodulecollector(self, testdir): item = testdir.getitem("def test_func(): pass") - modcol = item.getparent(py.test.collect.Module) - assert isinstance(modcol, py.test.collect.Module) + modcol = item.getparent(pytest.Module) + assert isinstance(modcol, pytest.Module) assert hasattr(modcol.obj, 'test_func') def test_function_equality(self, testdir, tmpdir): config = testdir.reparseconfig() 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) - f2 = py.test.collect.Function(name="name",config=config, + f2 = pytest.Function(name="name",config=config, args=(1,), callobj=py.builtin.callable, session=session) assert not 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) assert not f3 == f2 assert f3 != f2 @@ -220,7 +220,7 @@ class TestFunction: assert not 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) assert f1 == f1_b assert not f1 != f1_b @@ -236,9 +236,9 @@ class TestFunction: funcargs = {} id = "world" 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) - f5b = py.test.collect.Function(name="name", config=config, + f5b = pytest.Function(name="name", config=config, callspec=callspec2, callobj=isinstance, session=session) assert f5 != f5b assert not (f5 == f5b) @@ -263,9 +263,9 @@ class TestSorting: def test_fail(): assert 0 """) 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") - assert isinstance(fn2, py.test.collect.Function) + assert isinstance(fn2, pytest.Function) assert fn1 == fn2 assert fn1 != modcol @@ -274,7 +274,7 @@ class TestSorting: assert hash(fn1) == hash(fn2) 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 fn1 != fn3 @@ -309,8 +309,8 @@ class TestSorting: class TestConftestCustomization: def test_pytest_pycollect_module(self, testdir): testdir.makeconftest(""" - import py - class MyModule(py.test.collect.Module): + import pytest + class MyModule(pytest.Module): pass def pytest_pycollect_makemodule(path, parent): if path.basename == "test_xyz.py": @@ -326,8 +326,8 @@ class TestConftestCustomization: def test_pytest_pycollect_makeitem(self, testdir): testdir.makeconftest(""" - import py - class MyFunction(py.test.collect.Function): + import pytest + class MyFunction(pytest.Function): pass def pytest_pycollect_makeitem(collector, name, obj): if name == "some": @@ -342,7 +342,7 @@ class TestConftestCustomization: def test_makeitem_non_underscore(self, testdir, monkeypatch): modcol = testdir.getmodulecol("def _hello(): pass") l = [] - monkeypatch.setattr(py.test.collect.Module, 'makeitem', + monkeypatch.setattr(pytest.Module, 'makeitem', lambda self, name, obj: l.append(name)) l = modcol.collect() assert '_hello' not in l @@ -545,7 +545,7 @@ class TestFillFuncArgs: item.config.pluginmanager.register(Provider()) if hasattr(item, '_args'): del item._args - py.test.collect._fillfuncargs(item) + pytest._fillfuncargs(item) assert len(item.funcargs) == 1 class TestRequest: @@ -634,7 +634,7 @@ class TestRequest: req.config._setupstate.prepare(item) # XXX req._fillfuncargs() # successively check finalization calls - teardownlist = item.getparent(py.test.collect.Module).obj.teardownlist + teardownlist = item.getparent(pytest.Module).obj.teardownlist ss = item.config._setupstate assert not teardownlist 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 testdir.makeconftest(""" - import py + import pytest def pytest_pycollect_makeitem(collector, name, obj): if name == "MyClass": return MyCollector(name, parent=collector) - class MyCollector(py.test.collect.Collector): + class MyCollector(pytest.Collector): def reportinfo(self): return self.fspath, 3, "xyz" """) @@ -1048,8 +1048,8 @@ def test_funcarg_lookup_error(testdir): class TestReportInfo: def test_itemreport_reportinfo(self, testdir, linecomp): testdir.makeconftest(""" - import py - class MyFunction(py.test.collect.Function): + import pytest + class MyFunction(pytest.Function): def reportinfo(self): return "ABCDE", 42, "custom" def pytest_pycollect_makeitem(collector, name, obj): diff --git a/testing/plugin/test_runner.py b/testing/plugin/test_runner.py index a84ffb1a4..73a0c7247 100644 --- a/testing/plugin/test_runner.py +++ b/testing/plugin/test_runner.py @@ -141,8 +141,8 @@ class BaseFunctionalTests: def test_custom_failure_repr(self, testdir): testdir.makepyfile(conftest=""" - import py - class Function(py.test.collect.Function): + import pytest + class Function(pytest.Function): def repr_failure(self, excinfo): return "hello" """) @@ -162,13 +162,12 @@ class BaseFunctionalTests: def test_failure_in_setup_function_ignores_custom_repr(self, testdir): testdir.makepyfile(conftest=""" - import py - class Function(py.test.collect.Function): + import pytest + class Function(pytest.Function): def repr_failure(self, excinfo): assert 0 """) reports = testdir.runitem(""" - import py def setup_function(func): raise ValueError(42) def test_func(): @@ -200,9 +199,9 @@ class BaseFunctionalTests: def test_exit_propagates(self, testdir): try: testdir.runitem(""" - import py + import pytest def test_func(): - raise py.test.exit.Exception() + raise pytest.exit.Exception() """) except py.test.exit.Exception: pass @@ -267,8 +266,8 @@ class TestSessionReports: def test_skip_at_module_scope(self, testdir): col = testdir.getmodulecol(""" - import py - py.test.skip("hello") + import pytest + pytest.skip("hello") def test_func(): pass """) diff --git a/testing/plugin/test_session.py b/testing/plugin/test_session.py index 4597ba7e4..cde45b07d 100644 --- a/testing/plugin/test_session.py +++ b/testing/plugin/test_session.py @@ -1,4 +1,4 @@ -import py +import pytest, py class SessionTests: def test_basic_testitem_events(self, testdir): @@ -26,7 +26,7 @@ class SessionTests: colstarted = reprec.getcalls("pytest_collectstart") assert len(colstarted) == 1 + 1 col = colstarted[1].collector - assert isinstance(col, py.test.collect.Module) + assert isinstance(col, pytest.Module) def test_nested_import_error(self, testdir): tfile = testdir.makepyfile(""" @@ -94,7 +94,7 @@ class SessionTests: def test_broken_repr(self, testdir): p = testdir.makepyfile(""" - import py + import pytest class BrokenRepr1: foo=0 def __repr__(self): @@ -103,7 +103,7 @@ class SessionTests: class TestBrokenClass: def test_explicit_bad_repr(self): t = BrokenRepr1() - py.test.raises(Exception, 'repr(t)') + pytest.raises(Exception, 'repr(t)') def test_implicit_bad_repr1(self): t = BrokenRepr1() diff --git a/testing/test_collection.py b/testing/test_collection.py index 72e84ec32..86a0bca25 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1,10 +1,10 @@ -import py +import pytest, py from pytest.plugin.session import Session class TestCollector: 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(Item, Collector) @@ -14,15 +14,15 @@ class TestCollector: def test_fail(): assert 0 """) recwarn.clear() - assert modcol.Module == py.test.collect.Module + assert modcol.Module == pytest.Module recwarn.pop(DeprecationWarning) - assert modcol.Class == py.test.collect.Class + assert modcol.Class == pytest.Class recwarn.pop(DeprecationWarning) - assert modcol.Item == py.test.collect.Item + assert modcol.Item == pytest.Item recwarn.pop(DeprecationWarning) - assert modcol.File == py.test.collect.File + assert modcol.File == pytest.File recwarn.pop(DeprecationWarning) - assert modcol.Function == py.test.collect.Function + assert modcol.Function == pytest.Function recwarn.pop(DeprecationWarning) def test_check_equality(self, testdir): @@ -31,9 +31,9 @@ class TestCollector: def test_fail(): assert 0 """) 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") - assert isinstance(fn2, py.test.collect.Function) + assert isinstance(fn2, pytest.Function) assert fn1 == fn2 assert fn1 != modcol @@ -42,7 +42,7 @@ class TestCollector: assert hash(fn1) == hash(fn2) 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 fn1 != fn3 @@ -63,32 +63,32 @@ class TestCollector: fn = testdir.collect_by_name( testdir.collect_by_name(cls, "()"), "test_foo") - parent = fn.getparent(py.test.collect.Module) + parent = fn.getparent(pytest.Module) assert parent is modcol - parent = fn.getparent(py.test.collect.Function) + parent = fn.getparent(pytest.Function) assert parent is fn - parent = fn.getparent(py.test.collect.Class) + parent = fn.getparent(pytest.Class) assert parent is cls def test_getcustomfile_roundtrip(self, testdir): hello = testdir.makefile(".xxx", hello="world") testdir.makepyfile(conftest=""" - import py - class CustomFile(py.test.collect.File): + import pytest + class CustomFile(pytest.File): pass def pytest_collect_file(path, parent): if path.ext == ".xxx": return CustomFile(path, parent=parent) """) node = testdir.getpathnode(hello) - assert isinstance(node, py.test.collect.File) + assert isinstance(node, pytest.File) assert node.name == "hello.xxx" nodes = node.session.perform_collect([node.nodeid], genitems=False) assert len(nodes) == 1 - assert isinstance(nodes[0], py.test.collect.File) + assert isinstance(nodes[0], pytest.File) class TestCollectFS: def test_ignored_certain_directories(self, testdir): @@ -158,18 +158,18 @@ class TestPrunetraceback: import not_exists """) testdir.makeconftest(""" - import py + import pytest def pytest_collect_file(path, parent): return MyFile(path, parent) class MyError(Exception): pass - class MyFile(py.test.collect.File): + class MyFile(pytest.File): def collect(self): raise MyError() def repr_failure(self, excinfo): if excinfo.errisinstance(MyError): return "hello world" - return py.test.collect.File.repr_failure(self, excinfo) + return pytest.File.repr_failure(self, excinfo) """) result = testdir.runpytest(p) @@ -184,7 +184,7 @@ class TestPrunetraceback: import not_exists """) testdir.makeconftest(""" - import py + import pytest def pytest_make_collect_report(__multicall__): rep = __multicall__.execute() rep.headerlines += ["header1"] @@ -246,8 +246,8 @@ class TestCustomConftests: def test_pytest_fs_collect_hooks_are_seen(self, testdir): conf = testdir.makeconftest(""" - import py - class MyModule(py.test.collect.Module): + import pytest + class MyModule(pytest.Module): pass def pytest_collect_file(path, parent): if path.ext == ".py": @@ -265,8 +265,8 @@ class TestCustomConftests: sub1 = testdir.mkpydir("sub1") sub2 = testdir.mkpydir("sub2") conf1 = testdir.makeconftest(""" - import py - class MyModule1(py.test.collect.Module): + import pytest + class MyModule1(pytest.Module): pass def pytest_collect_file(path, parent): if path.ext == ".py": @@ -274,8 +274,8 @@ class TestCustomConftests: """) conf1.move(sub1.join(conf1.basename)) conf2 = testdir.makeconftest(""" - import py - class MyModule2(py.test.collect.Module): + import pytest + class MyModule2(pytest.Module): pass def pytest_collect_file(path, parent): if path.ext == ".py": @@ -378,11 +378,11 @@ class TestSession: def test_collect_custom_nodes_multi_id(self, testdir): p = testdir.makepyfile("def test_func(): pass") testdir.makeconftest(""" - import py - class SpecialItem(py.test.collect.Item): + import pytest + class SpecialItem(pytest.Item): def runtest(self): return # ok - class SpecialFile(py.test.collect.File): + class SpecialFile(pytest.File): def collect(self): return [SpecialItem(name="check", parent=self)] def pytest_collect_file(path, parent): @@ -481,7 +481,7 @@ class Test_getinitialnodes: x = tmpdir.ensure("x.py") config = testdir.reparseconfig([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.parent.name == testdir.tmpdir.basename assert col.parent.parent is None @@ -496,7 +496,7 @@ class Test_getinitialnodes: subdir.ensure("__init__.py") config = testdir.reparseconfig([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.parent.parent is None for col in col.listchain(): diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 2e4a3d3b4..7755399a2 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -52,7 +52,7 @@ class TestConftestValueAccessGlobal: def test_default_has_lower_prio(self, basedir): conftest = ConftestWithSetinitial(basedir.join("adir")) 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): conftest = ConftestWithSetinitial(basedir) diff --git a/testing/test_main.py b/testing/test_main.py index 7903b3549..2b28b5496 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -352,8 +352,8 @@ class TestPytestPluginInteractions: def test_namespace_early_from_import(self, testdir): p = testdir.makepyfile(""" - from py.test.collect import Item - from pytest.collect import Item as Item2 + from pytest import Item + from pytest import Item as Item2 assert Item is Item2 """) result = testdir.runpython(p)