當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。