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

@@ -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

View File

@@ -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

View File

@@ -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):

View File

@@ -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
""")

View File

@@ -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()

View File

@@ -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():

View File

@@ -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)

View File

@@ -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)