[svn r62997] some more tests, seems like temp test dirs are now more contained when doing distributed testing
--HG-- branch : trunk
This commit is contained in:
parent
c8d679ac95
commit
fc7abf0efe
|
@ -120,7 +120,10 @@ class Config(object):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
def ensuretemp(self, string, dir=True):
|
def ensuretemp(self, string, dir=True):
|
||||||
if self.basetemp is None:
|
return self.getbasetemp().ensure(string, dir=dir)
|
||||||
|
|
||||||
|
def getbasetemp(self):
|
||||||
|
if self.basetemp is None:
|
||||||
basetemp = self.option.basetemp
|
basetemp = self.option.basetemp
|
||||||
if basetemp:
|
if basetemp:
|
||||||
basetemp = py.path.local(basetemp)
|
basetemp = py.path.local(basetemp)
|
||||||
|
@ -128,8 +131,16 @@ class Config(object):
|
||||||
basetemp.mkdir()
|
basetemp.mkdir()
|
||||||
else:
|
else:
|
||||||
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
|
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
|
||||||
self.basetemp = basetemp
|
self.basetemp = basetemp
|
||||||
return self.basetemp.ensure(string, dir=dir)
|
return self.basetemp
|
||||||
|
|
||||||
|
def mktemp(self, basename, numbered=False):
|
||||||
|
basetemp = self.getbasetemp()
|
||||||
|
if not numbered:
|
||||||
|
return basetemp.mkdir(basename)
|
||||||
|
else:
|
||||||
|
return py.path.local.make_numbered_dir(prefix=basename + "-",
|
||||||
|
keep=0, rootdir=basetemp)
|
||||||
|
|
||||||
def getcolitems(self):
|
def getcolitems(self):
|
||||||
return [self.getfsnode(arg) for arg in self.args]
|
return [self.getfsnode(arg) for arg in self.args]
|
||||||
|
@ -215,6 +226,7 @@ class Config(object):
|
||||||
oldconfig = py.test.config
|
oldconfig = py.test.config
|
||||||
try:
|
try:
|
||||||
config_per_process = py.test.config = Config()
|
config_per_process = py.test.config = Config()
|
||||||
|
config_per_process.basetemp = self.mktemp("reparse", numbered=True)
|
||||||
config_per_process.parse(args)
|
config_per_process.parse(args)
|
||||||
return config_per_process
|
return config_per_process
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -84,14 +84,34 @@ class TestConfigCmdlineParsing:
|
||||||
opts = spec.split()
|
opts = spec.split()
|
||||||
yield check_conflict_option, opts
|
yield check_conflict_option, opts
|
||||||
|
|
||||||
|
class TestConfigTmpdir:
|
||||||
|
def test_getbasetemp(self, testdir):
|
||||||
|
config = testdir.Config()
|
||||||
|
config.basetemp = "hello"
|
||||||
|
config.getbasetemp() == "hello"
|
||||||
|
|
||||||
|
def test_mktemp(self, testdir):
|
||||||
|
config = testdir.Config()
|
||||||
|
config.basetemp = testdir.mkdir("hello")
|
||||||
|
tmp = config.mktemp("world")
|
||||||
|
assert tmp.relto(config.basetemp) == "world"
|
||||||
|
tmp = config.mktemp("this", numbered=True)
|
||||||
|
assert tmp.relto(config.basetemp).startswith("this")
|
||||||
|
tmp2 = config.mktemp("this", numbered=True)
|
||||||
|
assert tmp2.relto(config.basetemp).startswith("this")
|
||||||
|
assert tmp2 != tmp
|
||||||
|
|
||||||
|
def test_reparse(self, testdir):
|
||||||
|
config = testdir.Config()
|
||||||
|
config.basetemp = testdir.mkdir("my")
|
||||||
|
config2 = config._reparse([])
|
||||||
|
assert config2.getbasetemp().relto(config.basetemp)
|
||||||
|
config3 = config._reparse([])
|
||||||
|
assert config3.getbasetemp().relto(config.basetemp)
|
||||||
|
assert config2.basetemp != config3.basetemp
|
||||||
|
|
||||||
class TestConfigAPI:
|
class TestConfigAPI:
|
||||||
|
|
||||||
@py.test.mark.issue("ensuretemp should call config.maketemp(basename)")
|
|
||||||
def test_ensuretemp(self):
|
|
||||||
d1 = py.test.ensuretemp('hello')
|
|
||||||
d2 = py.test.ensuretemp('hello')
|
|
||||||
assert d1 == d2
|
|
||||||
assert d1.check(dir=1)
|
|
||||||
|
|
||||||
def test_config_getvalue_honours_conftest(self, testdir):
|
def test_config_getvalue_honours_conftest(self, testdir):
|
||||||
testdir.makepyfile(conftest="x=1")
|
testdir.makepyfile(conftest="x=1")
|
||||||
|
@ -313,4 +333,10 @@ def test_options_on_small_file_do_not_blow_up(testdir):
|
||||||
|
|
||||||
def test_default_bus():
|
def test_default_bus():
|
||||||
assert py.test.config.bus is py._com.pyplugins
|
assert py.test.config.bus is py._com.pyplugins
|
||||||
|
|
||||||
|
@py.test.mark.todo("test for deprecation")
|
||||||
|
def test_ensuretemp():
|
||||||
|
d1 = py.test.ensuretemp('hello')
|
||||||
|
d2 = py.test.ensuretemp('hello')
|
||||||
|
assert d1 == d2
|
||||||
|
assert d1.check(dir=1)
|
||||||
|
|
Loading…
Reference in New Issue