streamline some tests and overall reduce py.test.ensuretemp usage, note down issue about deprecation .
--HG-- branch : trunk
This commit is contained in:
parent
9be7d78fb1
commit
77b640d1b7
|
@ -7,6 +7,8 @@ Changes between 1.X and 1.1.1
|
||||||
- install 'py.test' and `py.which` with a ``-$VERSION`` suffix to
|
- install 'py.test' and `py.which` with a ``-$VERSION`` suffix to
|
||||||
disambiguate between Python3, python2.X, Jython and PyPy installed versions.
|
disambiguate between Python3, python2.X, Jython and PyPy installed versions.
|
||||||
|
|
||||||
|
- new "pytestconfig" funcarg allows access to test config object
|
||||||
|
|
||||||
- make py.test.* helpers provided by default plugins visible early -
|
- make py.test.* helpers provided by default plugins visible early -
|
||||||
works transparently both for pydoc and for interactive sessions
|
works transparently both for pydoc and for interactive sessions
|
||||||
which will regularly see e.g. py.test.mark and py.test.importorskip.
|
which will regularly see e.g. py.test.mark and py.test.importorskip.
|
||||||
|
|
17
ISSUES.txt
17
ISSUES.txt
|
@ -46,14 +46,6 @@ The test-report header should optionally show information
|
||||||
about the under-test package and versions/locations of
|
about the under-test package and versions/locations of
|
||||||
involved packages.
|
involved packages.
|
||||||
|
|
||||||
install py.test with interpreter-specific prefixes
|
|
||||||
--------------------------------------------------------
|
|
||||||
tags: feature
|
|
||||||
|
|
||||||
When installing under python3, jython or pypy-c it is
|
|
||||||
desirable to (additionally?) install py.test with
|
|
||||||
respective suffixes.
|
|
||||||
|
|
||||||
make node._checkcollectable more robust
|
make node._checkcollectable more robust
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
tags: bug 1.1.2
|
tags: bug 1.1.2
|
||||||
|
@ -101,3 +93,12 @@ A local test run of a "tests" directory may work
|
||||||
but a remote one fail because the tests directory
|
but a remote one fail because the tests directory
|
||||||
does not contain an "__init__.py". Either give
|
does not contain an "__init__.py". Either give
|
||||||
an error or make it work without the __init__.py
|
an error or make it work without the __init__.py
|
||||||
|
|
||||||
|
deprecate ensuretemp / introduce funcargs to setup method
|
||||||
|
--------------------------------------------------------------
|
||||||
|
tags: wish 1.1.2
|
||||||
|
|
||||||
|
The remaining uses of py.test.ensuretemp within the py-test base
|
||||||
|
itself are for setup methods. Also users have expressed the
|
||||||
|
wish to have funcargs available to setup functions. Experiment
|
||||||
|
with allowing funcargs there and finalizing deprecating py.test.ensuretemp.
|
||||||
|
|
|
@ -10,6 +10,7 @@ def ensuretemp(string, dir=1):
|
||||||
take care to provide empty unique directories for each
|
take care to provide empty unique directories for each
|
||||||
test call even if the test is called multiple times.
|
test call even if the test is called multiple times.
|
||||||
"""
|
"""
|
||||||
|
#py.log._apiwarn(">1.1", "use tmpdir function argument")
|
||||||
return py.test.config.ensuretemp(string, dir=dir)
|
return py.test.config.ensuretemp(string, dir=dir)
|
||||||
|
|
||||||
class CmdOptions(object):
|
class CmdOptions(object):
|
||||||
|
|
|
@ -28,6 +28,9 @@ def pytest_collect_file(path, parent):
|
||||||
if ext == ".py":
|
if ext == ".py":
|
||||||
return parent.Module(path, parent=parent)
|
return parent.Module(path, parent=parent)
|
||||||
|
|
||||||
|
def pytest_funcarg__pytestconfig(request):
|
||||||
|
return request.config
|
||||||
|
|
||||||
def pytest_collect_directory(path, parent):
|
def pytest_collect_directory(path, parent):
|
||||||
# XXX reconsider the following comment
|
# XXX reconsider the following comment
|
||||||
# not use parent.Directory here as we generally
|
# not use parent.Directory here as we generally
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
|
import sys, py
|
||||||
|
|
||||||
pytest_plugins = "pytest_pytester"
|
pytest_plugins = "pytest_pytester"
|
||||||
|
|
||||||
|
@py.test.mark.multi(name=[x for x in dir(py.cmdline) if x[0] != "_"])
|
||||||
|
def test_cmdmain(name):
|
||||||
|
main = getattr(py.cmdline, name)
|
||||||
|
assert py.builtin.callable(main)
|
||||||
|
assert name[:2] == "py"
|
||||||
|
scriptname = "py." + name[2:]
|
||||||
|
if sys.platform == "win32":
|
||||||
|
scriptname += ".exe"
|
||||||
|
assert py.path.local.sysfind(scriptname), scriptname
|
||||||
|
|
||||||
class TestPyLookup:
|
class TestPyLookup:
|
||||||
def test_basic(self, testdir):
|
def test_basic(self, testdir):
|
||||||
p = testdir.makepyfile(hello="def x(): pass")
|
p = testdir.makepyfile(hello="def x(): pass")
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
import py
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def setup_module(mod):
|
|
||||||
mod.binpath = py._impldir.dirpath('bin')
|
|
||||||
if not mod.binpath.check():
|
|
||||||
py.test.skip("bin-source scripts not installed")
|
|
||||||
mod.binwinpath = binpath.join("win32")
|
|
||||||
mod.tmpdir = py.test.ensuretemp(__name__)
|
|
||||||
mod.iswin32 = sys.platform == "win32"
|
|
||||||
|
|
||||||
def checkmain(name):
|
|
||||||
main = getattr(py.cmdline, name)
|
|
||||||
assert py.builtin.callable(main)
|
|
||||||
assert name[:2] == "py"
|
|
||||||
scriptname = "py." + name[2:]
|
|
||||||
assert binpath.join(scriptname).check()
|
|
||||||
assert binwinpath.join(scriptname + ".cmd").check()
|
|
||||||
|
|
||||||
def checkprocess(script):
|
|
||||||
assert script.check()
|
|
||||||
old = tmpdir.ensure(script.basename, dir=1).chdir()
|
|
||||||
try:
|
|
||||||
if iswin32:
|
|
||||||
cmd = script.basename
|
|
||||||
else:
|
|
||||||
cmd = "%s" %(script, )
|
|
||||||
# XXX distributed testing's rsync does not support
|
|
||||||
# syncing executable bits
|
|
||||||
script.chmod(int("777", 8))
|
|
||||||
|
|
||||||
if script.basename.startswith("py.lookup") or \
|
|
||||||
script.basename.startswith("py.which"):
|
|
||||||
cmd += " sys"
|
|
||||||
py.builtin.print_("executing", script)
|
|
||||||
try:
|
|
||||||
old = script.dirpath().chdir()
|
|
||||||
try:
|
|
||||||
py.process.cmdexec(cmd)
|
|
||||||
finally:
|
|
||||||
old.chdir()
|
|
||||||
except py.process.cmdexec.Error:
|
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if cmd.find("py.rest") != -1 and \
|
|
||||||
e.out.find("module named") != -1:
|
|
||||||
return
|
|
||||||
raise
|
|
||||||
|
|
||||||
finally:
|
|
||||||
old.chdir()
|
|
||||||
|
|
||||||
def test_cmdline_namespace():
|
|
||||||
for name in dir(py.cmdline):
|
|
||||||
if name[0] != "_":
|
|
||||||
yield checkmain, name
|
|
||||||
|
|
||||||
def test_script_invocation():
|
|
||||||
if iswin32:
|
|
||||||
scripts = binwinpath.listdir("py.*")
|
|
||||||
else:
|
|
||||||
scripts = binpath.listdir("py.*")
|
|
||||||
scripts = [x for x in scripts
|
|
||||||
if not x.basename.startswith("py.svnwcrevert")]
|
|
||||||
for script in scripts:
|
|
||||||
yield checkprocess, script
|
|
|
@ -256,16 +256,15 @@ def test_codepath_Queue_example():
|
||||||
assert path.check()
|
assert path.check()
|
||||||
|
|
||||||
class TestFormattedExcinfo:
|
class TestFormattedExcinfo:
|
||||||
def setup_method(self, method):
|
def pytest_funcarg__importasmod(self, request):
|
||||||
self.tmpdir = py.test.ensuretemp("%s_%s" %(
|
def importasmod(source):
|
||||||
self.__class__.__name__, method.__name__))
|
|
||||||
|
|
||||||
def importasmod(self, source):
|
|
||||||
source = py.code.Source(source)
|
source = py.code.Source(source)
|
||||||
modpath = self.tmpdir.join("mod.py")
|
tmpdir = request.getfuncargvalue("tmpdir")
|
||||||
self.tmpdir.ensure("__init__.py")
|
modpath = tmpdir.join("mod.py")
|
||||||
|
tmpdir.ensure("__init__.py")
|
||||||
modpath.write(source)
|
modpath.write(source)
|
||||||
return modpath.pyimport()
|
return modpath.pyimport()
|
||||||
|
return importasmod
|
||||||
|
|
||||||
def excinfo_from_exec(self, source):
|
def excinfo_from_exec(self, source):
|
||||||
source = py.code.Source(source).strip()
|
source = py.code.Source(source).strip()
|
||||||
|
@ -392,8 +391,8 @@ raise ValueError()
|
||||||
assert reprlocals.lines[2] == 'y = 5'
|
assert reprlocals.lines[2] == 'y = 5'
|
||||||
assert reprlocals.lines[3] == 'z = 7'
|
assert reprlocals.lines[3] == 'z = 7'
|
||||||
|
|
||||||
def test_repr_tracebackentry_lines(self):
|
def test_repr_tracebackentry_lines(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def func1():
|
def func1():
|
||||||
raise ValueError("hello\\nworld")
|
raise ValueError("hello\\nworld")
|
||||||
""")
|
""")
|
||||||
|
@ -423,8 +422,8 @@ raise ValueError()
|
||||||
assert loc.lineno == 3
|
assert loc.lineno == 3
|
||||||
#assert loc.message == "ValueError: hello"
|
#assert loc.message == "ValueError: hello"
|
||||||
|
|
||||||
def test_repr_tracebackentry_lines(self):
|
def test_repr_tracebackentry_lines(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def func1(m, x, y, z):
|
def func1(m, x, y, z):
|
||||||
raise ValueError("hello\\nworld")
|
raise ValueError("hello\\nworld")
|
||||||
""")
|
""")
|
||||||
|
@ -447,8 +446,8 @@ raise ValueError()
|
||||||
assert tw.lines[1] == "x = 5, y = 13"
|
assert tw.lines[1] == "x = 5, y = 13"
|
||||||
assert tw.lines[2] == "z = " + repr('z' * 120)
|
assert tw.lines[2] == "z = " + repr('z' * 120)
|
||||||
|
|
||||||
def test_repr_tracebackentry_short(self):
|
def test_repr_tracebackentry_short(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def func1():
|
def func1():
|
||||||
raise ValueError("hello")
|
raise ValueError("hello")
|
||||||
def entry():
|
def entry():
|
||||||
|
@ -470,8 +469,8 @@ raise ValueError()
|
||||||
assert lines[1] == ' raise ValueError("hello")'
|
assert lines[1] == ' raise ValueError("hello")'
|
||||||
assert lines[2] == 'E ValueError: hello'
|
assert lines[2] == 'E ValueError: hello'
|
||||||
|
|
||||||
def test_repr_tracebackentry_no(self):
|
def test_repr_tracebackentry_no(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def func1():
|
def func1():
|
||||||
raise ValueError("hello")
|
raise ValueError("hello")
|
||||||
def entry():
|
def entry():
|
||||||
|
@ -487,8 +486,8 @@ raise ValueError()
|
||||||
assert lines[0] == 'E ValueError: hello'
|
assert lines[0] == 'E ValueError: hello'
|
||||||
assert not lines[1:]
|
assert not lines[1:]
|
||||||
|
|
||||||
def test_repr_traceback_tbfilter(self):
|
def test_repr_traceback_tbfilter(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def f(x):
|
def f(x):
|
||||||
raise ValueError(x)
|
raise ValueError(x)
|
||||||
def entry():
|
def entry():
|
||||||
|
@ -502,8 +501,8 @@ raise ValueError()
|
||||||
reprtb = p.repr_traceback(excinfo)
|
reprtb = p.repr_traceback(excinfo)
|
||||||
assert len(reprtb.reprentries) == 3
|
assert len(reprtb.reprentries) == 3
|
||||||
|
|
||||||
def test_repr_traceback_and_excinfo(self):
|
def test_repr_traceback_and_excinfo(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def f(x):
|
def f(x):
|
||||||
raise ValueError(x)
|
raise ValueError(x)
|
||||||
def entry():
|
def entry():
|
||||||
|
@ -523,8 +522,8 @@ raise ValueError()
|
||||||
assert repr.reprcrash.path.endswith("mod.py")
|
assert repr.reprcrash.path.endswith("mod.py")
|
||||||
assert repr.reprcrash.message == "ValueError: 0"
|
assert repr.reprcrash.message == "ValueError: 0"
|
||||||
|
|
||||||
def test_repr_excinfo_addouterr(self):
|
def test_repr_excinfo_addouterr(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def entry():
|
def entry():
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
""")
|
""")
|
||||||
|
@ -536,8 +535,8 @@ raise ValueError()
|
||||||
assert twmock.lines[-1] == "content"
|
assert twmock.lines[-1] == "content"
|
||||||
assert twmock.lines[-2] == ("-", "title")
|
assert twmock.lines[-2] == ("-", "title")
|
||||||
|
|
||||||
def test_repr_excinfo_reprcrash(self):
|
def test_repr_excinfo_reprcrash(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def entry():
|
def entry():
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
""")
|
""")
|
||||||
|
@ -548,8 +547,8 @@ raise ValueError()
|
||||||
assert repr.reprcrash.message == "ValueError"
|
assert repr.reprcrash.message == "ValueError"
|
||||||
assert str(repr.reprcrash).endswith("mod.py:3: ValueError")
|
assert str(repr.reprcrash).endswith("mod.py:3: ValueError")
|
||||||
|
|
||||||
def test_repr_traceback_recursion(self):
|
def test_repr_traceback_recursion(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def rec2(x):
|
def rec2(x):
|
||||||
return rec1(x+1)
|
return rec1(x+1)
|
||||||
def rec1(x):
|
def rec1(x):
|
||||||
|
@ -565,12 +564,12 @@ raise ValueError()
|
||||||
assert reprtb.extraline == "!!! Recursion detected (same locals & position)"
|
assert reprtb.extraline == "!!! Recursion detected (same locals & position)"
|
||||||
assert str(reprtb)
|
assert str(reprtb)
|
||||||
|
|
||||||
def test_tb_entry_AssertionError(self):
|
def test_tb_entry_AssertionError(self, importasmod):
|
||||||
# probably this test is a bit redundant
|
# probably this test is a bit redundant
|
||||||
# as py/magic/testing/test_assertion.py
|
# as py/magic/testing/test_assertion.py
|
||||||
# already tests correctness of
|
# already tests correctness of
|
||||||
# assertion-reinterpretation logic
|
# assertion-reinterpretation logic
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def somefunc():
|
def somefunc():
|
||||||
x = 1
|
x = 1
|
||||||
assert x == 2
|
assert x == 2
|
||||||
|
@ -586,8 +585,8 @@ raise ValueError()
|
||||||
lines = reprentry.lines
|
lines = reprentry.lines
|
||||||
assert lines[-1] == "E assert 1 == 2"
|
assert lines[-1] == "E assert 1 == 2"
|
||||||
|
|
||||||
def test_reprexcinfo_getrepr(self):
|
def test_reprexcinfo_getrepr(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def f(x):
|
def f(x):
|
||||||
raise ValueError(x)
|
raise ValueError(x)
|
||||||
def entry():
|
def entry():
|
||||||
|
@ -601,8 +600,8 @@ raise ValueError()
|
||||||
assert isinstance(repr, ReprExceptionInfo)
|
assert isinstance(repr, ReprExceptionInfo)
|
||||||
assert repr.reprtraceback.style == style
|
assert repr.reprtraceback.style == style
|
||||||
|
|
||||||
def test_toterminal_long(self):
|
def test_toterminal_long(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def g(x):
|
def g(x):
|
||||||
raise ValueError(x)
|
raise ValueError(x)
|
||||||
def f():
|
def f():
|
||||||
|
@ -627,8 +626,8 @@ raise ValueError()
|
||||||
assert tw.lines[9] == ""
|
assert tw.lines[9] == ""
|
||||||
assert tw.lines[10].endswith("mod.py:3: ValueError")
|
assert tw.lines[10].endswith("mod.py:3: ValueError")
|
||||||
|
|
||||||
def test_toterminal_long_filenames(self):
|
def test_toterminal_long_filenames(self, importasmod):
|
||||||
mod = self.importasmod("""
|
mod = importasmod("""
|
||||||
def f():
|
def f():
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
""")
|
""")
|
||||||
|
@ -651,31 +650,22 @@ raise ValueError()
|
||||||
finally:
|
finally:
|
||||||
old.chdir()
|
old.chdir()
|
||||||
|
|
||||||
def test_format_excinfo(self):
|
@py.test.mark.multi(reproptions=[
|
||||||
mod = self.importasmod("""
|
{'style': style, 'showlocals': showlocals,
|
||||||
|
'funcargs': funcargs, 'tbfilter': tbfilter
|
||||||
|
} for style in ("long", "short", "no")
|
||||||
|
for showlocals in (True, False)
|
||||||
|
for tbfilter in (True, False)
|
||||||
|
for funcargs in (True, False)])
|
||||||
|
def test_format_excinfo(self, importasmod, reproptions):
|
||||||
|
mod = importasmod("""
|
||||||
def g(x):
|
def g(x):
|
||||||
raise ValueError(x)
|
raise ValueError(x)
|
||||||
def f():
|
def f():
|
||||||
g(3)
|
g(3)
|
||||||
""")
|
""")
|
||||||
excinfo = py.test.raises(ValueError, mod.f)
|
excinfo = py.test.raises(ValueError, mod.f)
|
||||||
def format_and_str(kw):
|
|
||||||
tw = py.io.TerminalWriter(stringio=True)
|
tw = py.io.TerminalWriter(stringio=True)
|
||||||
repr = excinfo.getrepr(**kw)
|
repr = excinfo.getrepr(**reproptions)
|
||||||
repr.toterminal(tw)
|
repr.toterminal(tw)
|
||||||
assert tw.stringio.getvalue()
|
assert tw.stringio.getvalue()
|
||||||
|
|
||||||
for combo in self.allcombos():
|
|
||||||
yield format_and_str, combo
|
|
||||||
|
|
||||||
def allcombos(self):
|
|
||||||
for style in ("long", "short", "no"):
|
|
||||||
for showlocals in (True, False):
|
|
||||||
for tbfilter in (True, False):
|
|
||||||
for funcargs in (True, False):
|
|
||||||
kw = {'style': style,
|
|
||||||
'showlocals': showlocals,
|
|
||||||
'funcargs': funcargs,
|
|
||||||
'tbfilter': tbfilter
|
|
||||||
}
|
|
||||||
yield kw
|
|
||||||
|
|
|
@ -310,10 +310,9 @@ def test_deindent():
|
||||||
assert lines == ['', 'def f():', ' def g():', ' pass', ' ']
|
assert lines == ['', 'def f():', ' def g():', ' pass', ' ']
|
||||||
|
|
||||||
@py.test.mark.xfail
|
@py.test.mark.xfail
|
||||||
def test_source_of_class_at_eof_without_newline():
|
def test_source_of_class_at_eof_without_newline(tmpdir):
|
||||||
# this test fails because the implicit inspect.getsource(A) below
|
# this test fails because the implicit inspect.getsource(A) below
|
||||||
# does not return the "x = 1" last line.
|
# does not return the "x = 1" last line.
|
||||||
tmpdir = py.test.ensuretemp("source_write_read")
|
|
||||||
source = py.code.Source('''
|
source = py.code.Source('''
|
||||||
class A(object):
|
class A(object):
|
||||||
def method(self):
|
def method(self):
|
||||||
|
|
|
@ -6,7 +6,6 @@ from py.impl.log.log import default_keywordmapper
|
||||||
callcapture = py.io.StdCapture.call
|
callcapture = py.io.StdCapture.call
|
||||||
|
|
||||||
def setup_module(mod):
|
def setup_module(mod):
|
||||||
mod.tempdir = py.test.ensuretemp("py.log-test")
|
|
||||||
mod._oldstate = default_keywordmapper.getstate()
|
mod._oldstate = default_keywordmapper.getstate()
|
||||||
|
|
||||||
def teardown_module(mod):
|
def teardown_module(mod):
|
||||||
|
@ -116,8 +115,8 @@ class TestLogConsumer:
|
||||||
assert not err
|
assert not err
|
||||||
assert out.strip() == '[xyz] hello'
|
assert out.strip() == '[xyz] hello'
|
||||||
|
|
||||||
def test_log_file(self):
|
def test_log_file(self, tmpdir):
|
||||||
customlog = tempdir.join('log.out')
|
customlog = tmpdir.join('log.out')
|
||||||
py.log.setconsumer("default", open(str(customlog), 'w', buffering=1))
|
py.log.setconsumer("default", open(str(customlog), 'w', buffering=1))
|
||||||
py.log.Producer("default")("hello world #1")
|
py.log.Producer("default")("hello world #1")
|
||||||
assert customlog.readlines() == ['[default] hello world #1\n']
|
assert customlog.readlines() == ['[default] hello world #1\n']
|
||||||
|
@ -127,8 +126,8 @@ class TestLogConsumer:
|
||||||
res = customlog.readlines()
|
res = customlog.readlines()
|
||||||
assert res == ['[default] hello world #2\n'] # no append by default!
|
assert res == ['[default] hello world #2\n'] # no append by default!
|
||||||
|
|
||||||
def test_log_file_append_mode(self):
|
def test_log_file_append_mode(self, tmpdir):
|
||||||
logfilefn = tempdir.join('log_append.out')
|
logfilefn = tmpdir.join('log_append.out')
|
||||||
|
|
||||||
# The append mode is on by default, so we don't need to specify it for File
|
# The append mode is on by default, so we don't need to specify it for File
|
||||||
py.log.setconsumer("default", py.log.Path(logfilefn, append=True,
|
py.log.setconsumer("default", py.log.Path(logfilefn, append=True,
|
||||||
|
@ -144,8 +143,8 @@ class TestLogConsumer:
|
||||||
assert lines == ['[default] hello world #1\n',
|
assert lines == ['[default] hello world #1\n',
|
||||||
'[default] hello world #1\n']
|
'[default] hello world #1\n']
|
||||||
|
|
||||||
def test_log_file_delayed_create(self):
|
def test_log_file_delayed_create(self, tmpdir):
|
||||||
logfilefn = tempdir.join('log_create.out')
|
logfilefn = tmpdir.join('log_create.out')
|
||||||
|
|
||||||
py.log.setconsumer("default", py.log.Path(logfilefn,
|
py.log.setconsumer("default", py.log.Path(logfilefn,
|
||||||
delayed_create=True, buffering=0))
|
delayed_create=True, buffering=0))
|
||||||
|
@ -154,11 +153,11 @@ class TestLogConsumer:
|
||||||
lines = logfilefn.readlines()
|
lines = logfilefn.readlines()
|
||||||
assert lines == ['[default] hello world #1\n']
|
assert lines == ['[default] hello world #1\n']
|
||||||
|
|
||||||
def test_keyword_based_log_files(self):
|
def test_keyword_based_log_files(self, tmpdir):
|
||||||
logfiles = []
|
logfiles = []
|
||||||
keywords = 'k1 k2 k3'.split()
|
keywords = 'k1 k2 k3'.split()
|
||||||
for key in keywords:
|
for key in keywords:
|
||||||
path = tempdir.join(key)
|
path = tmpdir.join(key)
|
||||||
py.log.setconsumer(key, py.log.Path(path, buffering=0))
|
py.log.setconsumer(key, py.log.Path(path, buffering=0))
|
||||||
|
|
||||||
py.log.Producer('k1')('1')
|
py.log.Producer('k1')('1')
|
||||||
|
@ -166,7 +165,7 @@ class TestLogConsumer:
|
||||||
py.log.Producer('k3')('3')
|
py.log.Producer('k3')('3')
|
||||||
|
|
||||||
for key in keywords:
|
for key in keywords:
|
||||||
path = tempdir.join(key)
|
path = tmpdir.join(key)
|
||||||
assert path.read().strip() == '[%s] %s' % (key, key[-1])
|
assert path.read().strip() == '[%s] %s' % (key, key[-1])
|
||||||
|
|
||||||
# disabled for now; the syslog log file can usually be read only by root
|
# disabled for now; the syslog log file can usually be read only by root
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
import py, sys
|
import py, sys
|
||||||
|
|
||||||
def test_kill():
|
def test_kill(tmpdir):
|
||||||
subprocess = py.test.importorskip("subprocess")
|
subprocess = py.test.importorskip("subprocess")
|
||||||
tmp = py.test.ensuretemp("test_kill")
|
t = tmpdir.join("t.py")
|
||||||
t = tmp.join("t.py")
|
|
||||||
t.write("import time ; time.sleep(100)")
|
t.write("import time ; time.sleep(100)")
|
||||||
proc = py.std.subprocess.Popen([sys.executable, str(t)])
|
proc = py.std.subprocess.Popen([sys.executable, str(t)])
|
||||||
assert proc.poll() is None # no return value yet
|
assert proc.poll() is None # no return value yet
|
||||||
|
|
|
@ -32,12 +32,12 @@ class TestGeneralUsage:
|
||||||
mytemp = testdir.tmpdir.mkdir("mytemp")
|
mytemp = testdir.tmpdir.mkdir("mytemp")
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
import py
|
import py
|
||||||
def test_1():
|
def test_1(pytestconfig):
|
||||||
py.test.ensuretemp('xyz')
|
pytestconfig.getbasetemp().ensure("hello")
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
assert mytemp.join('xyz').check(dir=1)
|
assert mytemp.join('hello').check()
|
||||||
|
|
||||||
def test_assertion_magic(self, testdir):
|
def test_assertion_magic(self, testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
|
|
@ -248,8 +248,8 @@ def test_options_on_small_file_do_not_blow_up(testdir):
|
||||||
['--traceconfig'], ['-v'], ['-v', '-v']):
|
['--traceconfig'], ['-v'], ['-v', '-v']):
|
||||||
runfiletest(opts + [path])
|
runfiletest(opts + [path])
|
||||||
|
|
||||||
def test_ensuretemp():
|
def test_ensuretemp(recwarn):
|
||||||
# XXX test for deprecation
|
#py.test.deprecated_call(py.test.ensuretemp, 'hello')
|
||||||
d1 = py.test.ensuretemp('hello')
|
d1 = py.test.ensuretemp('hello')
|
||||||
d2 = py.test.ensuretemp('hello')
|
d2 = py.test.ensuretemp('hello')
|
||||||
assert d1 == d2
|
assert d1 == d2
|
||||||
|
|
|
@ -8,7 +8,7 @@ def pytest_generate_tests(metafunc):
|
||||||
|
|
||||||
def pytest_funcarg__basedir(request):
|
def pytest_funcarg__basedir(request):
|
||||||
def basedirmaker(request):
|
def basedirmaker(request):
|
||||||
basedir = d = request.config.ensuretemp(request.param)
|
basedir = d = request.getfuncargvalue("tmpdir")
|
||||||
d.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
|
d.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
|
||||||
d.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
|
d.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
|
||||||
if request.param == "inpackage":
|
if request.param == "inpackage":
|
||||||
|
|
Loading…
Reference in New Issue