move config to _config

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-10-10 13:48:49 +02:00
parent 51bb0f53c5
commit 32fce34825
11 changed files with 41 additions and 33 deletions

View File

@ -3,16 +3,18 @@ extensible functional and unit testing with Python.
(c) Holger Krekel and others, 2004-2010 (c) Holger Krekel and others, 2004-2010
""" """
__version__ = "2.0.0dev0" __version__ = "2.0.0dev0"
import pytest.config import pytest._config
from pytest import collect from pytest import collect
__all__ = ['collect', 'cmdline']
class cmdline: # compatibility py.test.cmdline.main == pytest.cmdline.main class cmdline: # compatibility py.test.cmdline.main == pytest.cmdline.main
@staticmethod @staticmethod
def main(args=None): def main(args=None):
import sys import sys
if args is None: if args is None:
args = sys.argv[1:] args = sys.argv[1:]
config = pytest.config.Config() config = pytest._config.config_per_process = pytest._config.Config()
config.parse(args) config.parse(args)
try: try:
exitstatus = config.hook.pytest_cmdline_main(config=config) exitstatus = config.hook.pytest_cmdline_main(config=config)

View File

@ -215,16 +215,6 @@ class Conftest(object):
return mod return mod
def ensuretemp(string, dir=1):
""" (deprecated) return temporary directory path with
the given string as the trailing part. It is usually
better to use the 'tmpdir' function argument which will
take care to provide empty unique directories for each
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)
class CmdOptions(object): class CmdOptions(object):
""" holds cmdline options as attributes.""" """ holds cmdline options as attributes."""
def __init__(self, **kwargs): def __init__(self, **kwargs):

View File

@ -8,7 +8,7 @@ import re
import inspect import inspect
import time import time
from fnmatch import fnmatch from fnmatch import fnmatch
from pytest.config import Config as pytestConfig from pytest._config import Config as pytestConfig
from pytest.plugin.pytest_session import Collection from pytest.plugin.pytest_session import Collection
from py.builtin import print_ from py.builtin import print_
@ -222,15 +222,15 @@ class TmpTestdir:
""" this is used from tests that want to re-invoke parse(). """ """ this is used from tests that want to re-invoke parse(). """
if not args: if not args:
args = [self.tmpdir] args = [self.tmpdir]
from pytest import config from pytest import _config
oldconfig = config.config_per_process # py.test.config oldconfig = _config.config_per_process # py.test.config
try: try:
c = config.config_per_process = py.test.config = pytestConfig() c = _config.config_per_process = py.test.config = pytestConfig()
c.basetemp = oldconfig.mktemp("reparse", numbered=True) c.basetemp = oldconfig.mktemp("reparse", numbered=True)
c.parse(args) c.parse(args)
return c return c
finally: finally:
config.config_per_process = py.test.config = oldconfig _config.config_per_process = py.test.config = oldconfig
def parseconfigure(self, *args): def parseconfigure(self, *args):
config = self.parseconfig(*args) config = self.parseconfig(*args)

View File

@ -38,6 +38,7 @@ def pytest_configure(config):
if config.getvalue("exitfirst"): if config.getvalue("exitfirst"):
config.option.maxfail = 1 config.option.maxfail = 1
def pytest_cmdline_main(config): def pytest_cmdline_main(config):
return Session(config).main() return Session(config).main()

View File

@ -8,7 +8,19 @@ usage example::
.. _`py.path.local`: ../../path.html .. _`py.path.local`: ../../path.html
""" """
import py import pytest
def pytest_configure(config):
def ensuretemp(string, dir=1):
""" (deprecated) return temporary directory path with
the given string as the trailing part. It is usually
better to use the 'tmpdir' function argument which will
take care to provide empty unique directories for each
test call even if the test is called multiple times.
"""
#py.log._apiwarn(">1.1", "use tmpdir function argument")
return config.ensuretemp(string, dir=dir)
pytest.ensuretemp = ensuretemp
def pytest_funcarg__tmpdir(request): def pytest_funcarg__tmpdir(request):
"""return a temporary directory path object """return a temporary directory path object

View File

@ -137,9 +137,9 @@ class PluginManager(object):
mod = importplugin(modname) mod = importplugin(modname)
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
#except py.test.skip.Exception: except py.test.skip.Exception:
# e = py.std.sys.exc_info()[1] e = py.std.sys.exc_info()[1]
# self._hints.append("skipped plugin %r: %s" %((modname, e.msg))) self._hints.append("skipped plugin %r: %s" %((modname, e.msg)))
else: else:
check_old_use(mod, modname) check_old_use(mod, modname)
self.register(mod) self.register(mod)

View File

@ -1,3 +1,5 @@
import py
from pytest.plugin.pytest_tmpdir import pytest_funcarg__tmpdir from pytest.plugin.pytest_tmpdir import pytest_funcarg__tmpdir
from pytest.plugin.pytest_python import FuncargRequest from pytest.plugin.pytest_python import FuncargRequest
@ -7,3 +9,11 @@ def test_funcarg(testdir):
assert p.check() assert p.check()
bn = p.basename.strip("0123456789") bn = p.basename.strip("0123456789")
assert bn.endswith("test_func") assert bn.endswith("test_func")
def test_ensuretemp(recwarn):
#py.test.deprecated_call(py.test.ensuretemp, 'hello')
d1 = py.test.ensuretemp('hello')
d2 = py.test.ensuretemp('hello')
assert d1 == d2
assert d1.check(dir=1)

View File

@ -121,13 +121,6 @@ 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(recwarn):
#py.test.deprecated_call(py.test.ensuretemp, 'hello')
d1 = py.test.ensuretemp('hello')
d2 = py.test.ensuretemp('hello')
assert d1 == d2
assert d1.check(dir=1)
def test_preparse_ordering(testdir, monkeypatch): def test_preparse_ordering(testdir, monkeypatch):
pkg_resources = py.test.importorskip("pkg_resources") pkg_resources = py.test.importorskip("pkg_resources")
def my_iter(name): def my_iter(name):

View File

@ -1,5 +1,5 @@
import py import py
from pytest.config import Conftest from pytest._config import Conftest
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
if "basedir" in metafunc.funcargnames: if "basedir" in metafunc.funcargnames:

View File

@ -1,5 +1,5 @@
import py import py
from pytest import config as parseopt from pytest import _config as parseopt
class TestParser: class TestParser:
def test_init(self, capsys): def test_init(self, capsys):

View File

@ -232,7 +232,7 @@ class TestBootstrapping:
class TestPytestPluginInteractions: class TestPytestPluginInteractions:
def test_addhooks_conftestplugin(self, testdir): def test_addhooks_conftestplugin(self, testdir):
from pytest.config import Config from pytest._config import Config
newhooks = testdir.makepyfile(newhooks=""" newhooks = testdir.makepyfile(newhooks="""
def pytest_myhook(xyz): def pytest_myhook(xyz):
"new hook" "new hook"
@ -283,7 +283,7 @@ class TestPytestPluginInteractions:
]) ])
def test_do_option_conftestplugin(self, testdir): def test_do_option_conftestplugin(self, testdir):
from pytest.config import Config from pytest._config import Config
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption('--test123', action="store_true") parser.addoption('--test123', action="store_true")
@ -312,7 +312,7 @@ class TestPytestPluginInteractions:
]) ])
def test_do_option_postinitialize(self, testdir): def test_do_option_postinitialize(self, testdir):
from pytest.config import Config from pytest._config import Config
config = Config() config = Config()
config.parse([]) config.parse([])
config.pluginmanager.do_configure(config=config) config.pluginmanager.do_configure(config=config)