def test_hook_tracing(self):
        pytestpm = get_config().pluginmanager  # fully initialized with plugins
        saveindent = []

        class api1(object):
            def pytest_plugin_registered(self):
                saveindent.append(pytestpm.trace.root.indent)

        class api2(object):
            def pytest_plugin_registered(self):
                saveindent.append(pytestpm.trace.root.indent)
                raise ValueError()

        values = []
        pytestpm.trace.root.setwriter(values.append)
        undo = pytestpm.enable_tracing()
        try:
            indent = pytestpm.trace.root.indent
            p = api1()
            pytestpm.register(p)
            assert pytestpm.trace.root.indent == indent
            assert len(values) >= 2
            assert 'pytest_plugin_registered' in values[0]
            assert 'finish' in values[1]

            values[:] = []
            with pytest.raises(ValueError):
                pytestpm.register(api2())
            assert pytestpm.trace.root.indent == indent
            assert saveindent[0] > indent
        finally:
            undo()
 def test_addhooks_conftestplugin(self, testdir):
     testdir.makepyfile(
         newhooks="""
         def pytest_myhook(xyz):
             "new hook"
     """
     )
     conf = testdir.makeconftest(
         """
         import newhooks
         def pytest_addhooks(pluginmanager):
             pluginmanager.addhooks(newhooks)
         def pytest_myhook(xyz):
             return xyz + 1
     """
     )
     config = get_config()
     pm = config.pluginmanager
     pm.hook.pytest_addhooks.call_historic(
         kwargs=dict(pluginmanager=config.pluginmanager)
     )
     config.pluginmanager._importconftest(conf)
     # print(config.pluginmanager.get_plugins())
     res = config.hook.pytest_myhook(xyz=10)
     assert res == [11]
Beispiel #3
0
    def test_override_ini_does_not_contain_paths(self):
        """Check that -o no longer swallows all options after it (#3103)"""
        from _pytest.config import get_config

        config = get_config()
        config._preparse(["-o", "cache_dir=/cache", "/some/test/path"])
        assert config._override_ini == ["cache_dir=/cache"]
Beispiel #4
0
 def test_addopts_before_initini(self, monkeypatch):
     cache_dir = '.custom_cache'
     monkeypatch.setenv('PYTEST_ADDOPTS', '-o cache_dir=%s' % cache_dir)
     from _pytest.config import get_config
     config = get_config()
     config._preparse([], addopts=True)
     assert config._override_ini == ['cache_dir=%s' % cache_dir]
Beispiel #5
0
 def test_addopts_before_initini(self, monkeypatch):
     cache_dir = '.custom_cache'
     monkeypatch.setenv('PYTEST_ADDOPTS', '-o cache_dir=%s' % cache_dir)
     from _pytest.config import get_config
     config = get_config()
     config._preparse([], addopts=True)
     assert config._override_ini == ['cache_dir=%s' % cache_dir]
Beispiel #6
0
 def test_addhooks_conftestplugin(self, testdir):
     testdir.makepyfile(
         newhooks="""
         def pytest_myhook(xyz):
             "new hook"
     """
     )
     conf = testdir.makeconftest(
         """
         import sys ; sys.path.insert(0, '.')
         import newhooks
         def pytest_addhooks(pluginmanager):
             pluginmanager.addhooks(newhooks)
         def pytest_myhook(xyz):
             return xyz + 1
     """
     )
     config = get_config()
     pm = config.pluginmanager
     pm.hook.pytest_addhooks.call_historic(
         kwargs=dict(pluginmanager=config.pluginmanager)
     )
     config.pluginmanager._importconftest(conf)
     # print(config.pluginmanager.get_plugins())
     res = config.hook.pytest_myhook(xyz=10)
     assert res == [11]
Beispiel #7
0
    def test_override_ini_does_not_contain_paths(self):
        """Check that -o no longer swallows all options after it (#3103)"""
        from _pytest.config import get_config

        config = get_config()
        config._preparse(["-o", "cache_dir=/cache", "/some/test/path"])
        assert config._override_ini == ["cache_dir=/cache"]
Beispiel #8
0
    def test_addopts_from_env_not_concatenated(self, monkeypatch):
        """PYTEST_ADDOPTS should not take values from normal args (#4265)."""
        from _pytest.config import get_config

        monkeypatch.setenv("PYTEST_ADDOPTS", "-o")
        config = get_config()
        with pytest.raises(SystemExit) as excinfo:
            config._preparse(["cache_dir=ignored"], addopts=True)
        assert excinfo.value.args[0] == _pytest.main.EXIT_USAGEERROR
Beispiel #9
0
    def test_addopts_from_env_not_concatenated(self, monkeypatch):
        """PYTEST_ADDOPTS should not take values from normal args (#4265)."""
        from _pytest.config import get_config

        monkeypatch.setenv("PYTEST_ADDOPTS", "-o")
        config = get_config()
        with pytest.raises(UsageError) as excinfo:
            config._preparse(["cache_dir=ignored"], addopts=True)
        assert (
            "error: argument -o/--override-ini: expected one argument (via PYTEST_ADDOPTS)"
            in excinfo.value.args[0])
Beispiel #10
0
def test_load_initial_conftest_last_ordering(testdir):
    from _pytest.config  import get_config
    pm = get_config().pluginmanager
    class My:
        def pytest_load_initial_conftests(self):
            pass
    m = My()
    pm.register(m)
    hc = pm.hook.pytest_load_initial_conftests
    l = hc._nonwrappers + hc._wrappers
    assert l[-1].function.__module__ == "_pytest.capture"
    assert l[-2].function == m.pytest_load_initial_conftests
    assert l[-3].function.__module__ == "_pytest.config"
Beispiel #11
0
def test_load_initial_conftest_last_ordering(testdir):
    from _pytest.config  import get_config
    pm = get_config().pluginmanager
    class My:
        def pytest_load_initial_conftests(self):
            pass
    m = My()
    pm.register(m)
    hc = pm.hook.pytest_load_initial_conftests
    l = hc._nonwrappers + hc._wrappers
    assert l[-1].function.__module__ == "_pytest.capture"
    assert l[-2].function == m.pytest_load_initial_conftests
    assert l[-3].function.__module__ == "_pytest.config"
Beispiel #12
0
    def test_consider_module_import_module(self, testdir):
        pytestpm = get_config().pluginmanager
        mod = types.ModuleType("x")
        mod.pytest_plugins = "pytest_a"
        aplugin = testdir.makepyfile(pytest_a="#")
        reprec = testdir.make_hook_recorder(pytestpm)
        testdir.syspathinsert(aplugin.dirpath())
        pytestpm.consider_module(mod)
        call = reprec.getcall(pytestpm.hook.pytest_plugin_registered.name)
        assert call.plugin.__name__ == "pytest_a"

        # check that it is not registered twice
        pytestpm.consider_module(mod)
        values = reprec.getcalls("pytest_plugin_registered")
        assert len(values) == 1
Beispiel #13
0
 def __init__(self, mode=None):
     self.calls = {}
     self._run = None
     self._done = True
     self._wl = wandb.setup()
     self.record_q = self._wl._multiprocessing.Queue()
     self.result_q = self._wl._multiprocessing.Queue()
     self.interface = None
     self.last_queued = None
     self.history = []
     self.summary = {}
     self.config = {}
     self.files = {}
     self.mocker = _get_mock_module(get_config())
     self._internal_pid = None
Beispiel #14
0
    def test_consider_module_import_module(self, testdir):
        pytestpm = get_config().pluginmanager
        mod = types.ModuleType("x")
        mod.pytest_plugins = "pytest_a"
        aplugin = testdir.makepyfile(pytest_a="#")
        reprec = testdir.make_hook_recorder(pytestpm)
        testdir.syspathinsert(aplugin.dirpath())
        pytestpm.consider_module(mod)
        call = reprec.getcall(pytestpm.hook.pytest_plugin_registered.name)
        assert call.plugin.__name__ == "pytest_a"

        # check that it is not registered twice
        pytestpm.consider_module(mod)
        values = reprec.getcalls("pytest_plugin_registered")
        assert len(values) == 1
Beispiel #15
0
def test_load_initial_conftest_last_ordering(testdir):
    from _pytest.config import get_config

    pm = get_config().pluginmanager

    class My(object):
        def pytest_load_initial_conftests(self):
            pass

    m = My()
    pm.register(m)
    hc = pm.hook.pytest_load_initial_conftests
    values = hc._nonwrappers + hc._wrappers
    expected = ["_pytest.config", "test_config", "_pytest.capture"]
    assert [x.function.__module__ for x in values] == expected
Beispiel #16
0
def test_load_initial_conftest_last_ordering(testdir):
    from _pytest.config import get_config

    pm = get_config().pluginmanager

    class My(object):
        def pytest_load_initial_conftests(self):
            pass

    m = My()
    pm.register(m)
    hc = pm.hook.pytest_load_initial_conftests
    values = hc._nonwrappers + hc._wrappers
    expected = ["_pytest.config", "test_config", "_pytest.capture"]
    assert [x.function.__module__ for x in values] == expected
Beispiel #17
0
 def __init__(self, mode=None):
     self.calls = {}
     self._run = None
     self._done = True
     self._wl = wandb.setup()
     self.process_queue = self._wl._multiprocessing.Queue()
     self.req_queue = self._wl._multiprocessing.Queue()
     self.resp_queue = self._wl._multiprocessing.Queue()
     self.cancel_queue = self._wl._multiprocessing.Queue()
     self.notify_queue = self._wl._multiprocessing.Queue()
     self.interface = None
     self.last_queued = None
     self.history = []
     self.summary = {}
     self.config = {}
     self.files = {}
     self.mocker = _get_mock_module(get_config())
Beispiel #18
0
 def __init__(self, mode=None, settings=None, log_level=None):
     self.calls = {}
     self._run = None
     self._done = True
     self._multiprocessing = multiprocessing
     self.record_q = self._multiprocessing.Queue()
     self.result_q = self._multiprocessing.Queue()
     self.interface = None
     self.last_queued = None
     self.history = []
     self.summary = {}
     self.config = {}
     self.files = {}
     self.mocker = _get_mock_module(get_config())
     self._internal_pid = None
     self._settings = settings
     self._log_level = log_level
Beispiel #19
0
def _init_config(slave_options, slave_args):
    # Create a pytest Config based on options/args parsed in the master
    # This is a slightly modified form of _pytest.config.Config.fromdictargs
    # yaml is able to pack up the entire CmdOptions call from pytest, so
    # we can just set config.option to what was passed from the master in the slave_config yaml
    import pytest  # NOQA
    from _pytest.config import get_config
    config = get_config()
    config.args = slave_args
    config._preparse(config.args, addopts=False)
    config.option = slave_options
    # The master handles the result log, slaves shouldn't also write to it
    config.option['resultlog'] = None
    # Unset appliances to prevent the slaves from starting distributes tests :)
    config.option.appliances = []
    for pluginarg in config.option.plugins:
        config.pluginmanager.consider_pluginarg(pluginarg)
    config.pluginmanager.consider_pluginarg('no:fixtures.parallelizer')
    return config
Beispiel #20
0
def _init_config(slave_options, slave_args):
    # Create a pytest Config based on options/args parsed in the master
    # This is a slightly modified form of _pytest.config.Config.fromdictargs
    # yaml is able to pack up the entire CmdOptions call from pytest, so
    # we can just set config.option to what was passed from the master in the slave_config yaml
    import pytest  # NOQA
    from _pytest.config import get_config
    config = get_config()
    config.args = slave_args
    config._preparse(config.args, addopts=False)
    config.option = slave_options
    # The master handles the result log, slaves shouldn't also write to it
    config.option['resultlog'] = None
    # Unset appliances to prevent the slaves from starting distributes tests :)
    config.option.appliances = []
    for pluginarg in config.option.plugins:
        config.pluginmanager.consider_pluginarg(pluginarg)
    config.pluginmanager.consider_pluginarg('no:fixtures.parallelizer')
    return config
Beispiel #21
0
 def real_prepare_config(args=None, plugins=None):
     if args is None:
         args = sys.argv[1:]
     elif isinstance(args, py.path.local):
         args = [str(args)]
     elif not isinstance(args, (tuple, list)):
         if not isinstance(args, string_types):
             raise ValueError("not a string or argument list: %r" %
                              (args, ))
         args = shlex.split(args, posix=sys.platform != "win32")
     config = get_config()
     pluginmanager = config.pluginmanager
     try:
         if plugins:
             for plugin in plugins:
                 if isinstance(plugin, py.builtin._basestring):
                     pluginmanager.consider_pluginarg(plugin)
                 else:
                     pluginmanager.register(plugin)
         return pluginmanager.hook.pytest_cmdline_parse(
             pluginmanager=pluginmanager, args=args)
     except BaseException:
         config._ensure_unconfigure()
         raise
Beispiel #22
0
def make_assertion_hook():
    c = config.get_config()
    c.parse([])
    return install_importhook(c)
Beispiel #23
0
def _config_for_test():
    from _pytest.config import get_config

    config = get_config()
    yield config
    config._ensure_unconfigure()  # cleanup, e.g. capman closing tmpfiles.
Beispiel #24
0
def _config_for_test():
    from _pytest.config import get_config

    config = get_config()
    yield config
    config._ensure_unconfigure()  # cleanup, e.g. capman closing tmpfiles.
Beispiel #25
0
def make_assertion_hook():
    c = config.get_config()
    c.parse([])
    return install_importhook(c)