当前位置: 首页>>代码示例>>Python>>正文


Python pytest.exit方法代码示例

本文整理汇总了Python中pytest.exit方法的典型用法代码示例。如果您正苦于以下问题:Python pytest.exit方法的具体用法?Python pytest.exit怎么用?Python pytest.exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytest的用法示例。


在下文中一共展示了pytest.exit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forked_run_report

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def forked_run_report(item):
    # for now, we run setup/teardown in the subprocess
    # XXX optionally allow sharing of setup/teardown
    from _pytest.runner import runtestprotocol
    EXITSTATUS_TESTEXIT = 4
    import marshal

    def runforked():
        try:
            reports = runtestprotocol(item, log=False)
        except KeyboardInterrupt:
            os._exit(EXITSTATUS_TESTEXIT)
        return marshal.dumps([serialize_report(x) for x in reports])

    ff = py.process.ForkedFunc(runforked)
    result = ff.waitfinish()
    if result.retval is not None:
        report_dumps = marshal.loads(result.retval)
        return [runner.TestReport(**x) for x in report_dumps]
    else:
        if result.exitstatus == EXITSTATUS_TESTEXIT:
            pytest.exit("forked test item %s raised Exit" % (item,))
        return [report_process_crash(item, result)] 
开发者ID:pytest-dev,项目名称:pytest-forked,代码行数:25,代码来源:__init__.py

示例2: test_exit_outcome

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_exit_outcome(testdir):
    testdir.makepyfile(
        test_foo="""
        import pytest
        import unittest

        class MyTestCase(unittest.TestCase):
            def test_exit_outcome(self):
                pytest.exit("pytest_exit called")

            def test_should_not_run(self):
                pass
    """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(["*Exit: pytest_exit called*", "*= no tests ran in *"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:18,代码来源:test_unittest.py

示例3: test_wrap_session_exit_sessionfinish

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_wrap_session_exit_sessionfinish(
    returncode: Optional[int], testdir: Testdir
) -> None:
    testdir.makeconftest(
        """
        import pytest
        def pytest_sessionfinish():
            pytest.exit(msg="exit_pytest_sessionfinish", returncode={returncode})
    """.format(
            returncode=returncode
        )
    )
    result = testdir.runpytest()
    if returncode:
        assert result.ret == returncode
    else:
        assert result.ret == ExitCode.NO_TESTS_COLLECTED
    assert result.stdout.lines[-1] == "collected 0 items"
    assert result.stderr.lines == ["Exit: exit_pytest_sessionfinish"] 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:test_main.py

示例4: test_create_oneway_exit

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_create_oneway_exit(client):
    vil = await client.setup_user('vilmibm')
    await client.assert_next('STATE', 'STATE')
    sanctum = GameObject.get(
        GameObject.author==vil,
        GameObject.is_sanctum==True)
    GameWorld.put_into(sanctum, vil.player_obj)

    await client.assert_next('STATE', 'STATE', 'STATE')

    await client.send('COMMAND create exit "Rusty Door" east god/foyer A rusted, metal door', [
        'COMMAND OK',
        'STATE',
        'STATE',
        'You breathed light into a whole new exit'])
    await client.send('COMMAND go east', [
        'STATE',
        'COMMAND OK',
        'STATE',
        'STATE',
        'STATE',
        'You materialize'])

    foyer = GameObject.get(GameObject.shortname=='god/foyer')
    assert vil.player_obj in foyer.contains 
开发者ID:vilmibm,项目名称:tildemush,代码行数:27,代码来源:async_test.py

示例5: test_download_and_extract_brown_zip_file

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_download_and_extract_brown_zip_file():  # pragma: no cover
    """pytest runs tests in the same order they are defined in the test
    module, and so this test for downloading and unzipping the Brown zip
    data file runs first. If download fails, abort all tests."""
    try:
        with open(REMOTE_BROWN_ZIP_PATH, "wb") as f:
            with requests.get(REMOTE_BROWN_URL) as r:
                f.write(r.content)
    except Exception as e:
        msg = (
            "Error in downloading {}: "
            "network problems or invalid URL for Brown zip? "
            "If URL needs updating, tutorial.rst in docs "
            "has to be updated as well.".format(REMOTE_BROWN_URL)
        )
        try:
            raise e
        finally:
            pytest.exit(msg)
    else:
        # If download succeeds, unzip the Brown zip file.
        with zipfile.ZipFile(REMOTE_BROWN_ZIP_PATH) as zip_file:
            zip_file.extractall()
        # TODO compare the local eve.cha and CHILDES's 010600a.cha
        # if there are differences, CHILDES has updated data and may break us 
开发者ID:jacksonllee,项目名称:pylangacq,代码行数:27,代码来源:test_chat.py

示例6: check_required_loopback_interfaces_available

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def check_required_loopback_interfaces_available():
    """
    We need at least 3 loopback interfaces configured to run almost all dtests. On Linux, loopback
    interfaces are automatically created as they are used, but on Mac they need to be explicitly
    created. Check if we're running on Mac (Darwin), and if so check we have at least 3 loopback
    interfaces available, otherwise bail out so we don't run the tests in a known bad config and
    give the user some helpful advice on how to get their machine into a good known config
    """
    if platform.system() == "Darwin":
        if len(ni.ifaddresses('lo0')[AF_INET]) < 9:
            pytest.exit("At least 9 loopback interfaces are required to run dtests. "
                            "On Mac you can create the required loopback interfaces by running "
                            "'for i in {1..9}; do sudo ifconfig lo0 alias 127.0.0.$i up; done;'") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:15,代码来源:conftest.py

示例7: dtest_config

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def dtest_config(request):
    dtest_config = DTestConfig()
    dtest_config.setup(request)

    # if we're on mac, check that we have the required loopback interfaces before doing anything!
    check_required_loopback_interfaces_available()

    try:
        if dtest_config.cassandra_dir is not None:
            validate_install_dir(dtest_config.cassandra_dir)
    except Exception as e:
        pytest.exit("{}. Did you remember to build C*? ('ant clean jar')".format(e))

    yield dtest_config 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:16,代码来源:conftest.py

示例8: test_exit_propagates

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_exit_propagates(self, testdir) -> None:
        try:
            testdir.runitem(
                """
                import pytest
                def test_func():
                    raise pytest.exit.Exception()
            """
            )
        except pytest.exit.Exception:
            pass
        else:
            assert False, "did not raise" 
开发者ID:pytest-dev,项目名称:pytest,代码行数:15,代码来源:test_runner.py

示例9: test_pytest_exit

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_pytest_exit() -> None:
    with pytest.raises(pytest.exit.Exception) as excinfo:
        pytest.exit("hello")
    assert excinfo.errisinstance(pytest.exit.Exception) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:6,代码来源:test_runner.py

示例10: test_pytest_exit_msg

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_pytest_exit_msg(testdir) -> None:
    testdir.makeconftest(
        """
    import pytest

    def pytest_configure(config):
        pytest.exit('oh noes')
    """
    )
    result = testdir.runpytest()
    result.stderr.fnmatch_lines(["Exit: oh noes"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:13,代码来源:test_runner.py

示例11: test_pytest_exit_returncode

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def test_pytest_exit_returncode(testdir) -> None:
    testdir.makepyfile(
        """\
        import pytest
        def test_foo():
            pytest.exit("some exit msg", 99)
    """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"])

    assert _strip_resource_warnings(result.stderr.lines) == []
    assert result.ret == 99

    # It prints to stderr also in case of exit during pytest_sessionstart.
    testdir.makeconftest(
        """\
        import pytest

        def pytest_sessionstart():
            pytest.exit("during_sessionstart", 98)
        """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"])
    assert _strip_resource_warnings(result.stderr.lines) == [
        "Exit: during_sessionstart"
    ]
    assert result.ret == 98 
开发者ID:pytest-dev,项目名称:pytest,代码行数:31,代码来源:test_runner.py

示例12: _stop_if_necessary

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def _stop_if_necessary(self):
        """
        Stop tests if any error occurs.

        :return: None
        """
        try:
            exc, msg, tb = self._errors.get(False)
            traceback.print_exception(exc, msg, tb)
            sys.stderr.flush()
            if not self.ignore_errors:
                pytest.exit(msg)
        except queue.Empty:
            pass 
开发者ID:reportportal,项目名称:agent-python-pytest,代码行数:16,代码来源:service.py

示例13: pytest_configure

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def pytest_configure(config):
    # Patch pytest-trio
    patch_pytest_trio()
    # Configure structlog to redirect everything in logging
    structlog.configure(
        logger_factory=structlog.stdlib.LoggerFactory(),
        processors=[
            structlog.processors.StackInfoRenderer(),
            structlog.processors.format_exc_info,
            structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"),
            structlog.stdlib.add_logger_name,
            structlog.stdlib.add_log_level,
            structlog.dev.ConsoleRenderer(),
        ],
    )
    # Lock configuration
    structlog.configure = lambda *args, **kwargs: None
    # Add helper to caplog
    patch_caplog()
    if config.getoption("--run-postgresql-cluster"):
        pgurl = bootstrap_postgresql_testbed()
        capturemanager = config.pluginmanager.getplugin("capturemanager")
        if capturemanager:
            capturemanager.suspend(in_=True)
        print(f"usage: PG_URL={pgurl} py.test --postgresql tests")
        input("Press enter when you're done with...")
        pytest.exit("bye")
    elif config.getoption("--postgresql") and not is_xdist_master(config):
        bootstrap_postgresql_testbed() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:31,代码来源:conftest.py

示例14: check

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def check(self):
        cmd = ShellCommand("kubectl", "exec", self.path.k8s, "cat", self.log_path)
        if not cmd.check("check envoy access log"):
            pytest.exit("envoy access log does not exist")

        for line in cmd.stdout.splitlines():
            assert access_log_entry_regex.match(line), f"{line} does not match {access_log_entry_regex}" 
开发者ID:datawire,项目名称:ambassador,代码行数:9,代码来源:t_envoy_logs.py

示例15: queries

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import exit [as 别名]
def queries(self):
        if DEV:
            cmd = ShellCommand("docker", "ps", "-qf", "name=%s" % self.path.k8s)

            if not cmd.check(f'docker check for {self.path.k8s}'):
                if not cmd.stdout.strip():
                    log_cmd = ShellCommand("docker", "logs", self.path.k8s, stderr=subprocess.STDOUT)

                    if log_cmd.check(f'docker logs for {self.path.k8s}'):
                        print(cmd.stdout)

                    pytest.exit(f'container failed to start for {self.path.k8s}')

        return () 
开发者ID:datawire,项目名称:ambassador,代码行数:16,代码来源:abstract_tests.py


注:本文中的pytest.exit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。