當前位置: 首頁>>代碼示例>>Python>>正文


Python pytest.__file__方法代碼示例

本文整理匯總了Python中pytest.__file__方法的典型用法代碼示例。如果您正苦於以下問題:Python pytest.__file__方法的具體用法?Python pytest.__file__怎麽用?Python pytest.__file__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pytest的用法示例。


在下文中一共展示了pytest.__file__方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pytest_report_header

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def pytest_report_header(config):
    lines = []
    if config.option.debug or config.option.traceconfig:
        lines.append(
            "using: pytest-{} pylib-{}".format(pytest.__version__, py.__version__)
        )

        verinfo = getpluginversioninfo(config)
        if verinfo:
            lines.extend(verinfo)

    if config.option.traceconfig:
        lines.append("active plugins:")
        items = config.pluginmanager.list_name_plugin()
        for name, plugin in items:
            if hasattr(plugin, "__file__"):
                r = plugin.__file__
            else:
                r = repr(plugin)
            lines.append("    {:<20}: {}".format(name, r))
    return lines 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:23,代碼來源:helpconfig.py

示例2: pytest_report_header

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def pytest_report_header(config: Config) -> List[str]:
    lines = []
    if config.option.debug or config.option.traceconfig:
        lines.append(
            "using: pytest-{} pylib-{}".format(pytest.__version__, py.__version__)
        )

        verinfo = getpluginversioninfo(config)
        if verinfo:
            lines.extend(verinfo)

    if config.option.traceconfig:
        lines.append("active plugins:")
        items = config.pluginmanager.list_name_plugin()
        for name, plugin in items:
            if hasattr(plugin, "__file__"):
                r = plugin.__file__
            else:
                r = repr(plugin)
            lines.append("    {:<20}: {}".format(name, r))
    return lines 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:23,代碼來源:helpconfig.py

示例3: test_smoke_get_entrypoints

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_smoke_get_entrypoints():
    class FakeVenv:
        lib_path = Path(pytest.__file__).parent.parent
        bin_path = None

    entrypoints = get_entrypoints(venv=FakeVenv, name='pytest')
    assert len(entrypoints) == 2
    assert {e.name for e in entrypoints} == {'pytest', 'py.test'}
    assert {e.path for e in entrypoints} == {'pytest:main'} 
開發者ID:dephell,項目名稱:dephell,代碼行數:11,代碼來源:test_entrypoints.py

示例4: showversion

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def showversion(config):
    p = py.path.local(pytest.__file__)
    sys.stderr.write(
        "This is pytest version {}, imported from {}\n".format(pytest.__version__, p)
    )
    plugininfo = getpluginversioninfo(config)
    if plugininfo:
        for line in plugininfo:
            sys.stderr.write(line + "\n") 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:11,代碼來源:helpconfig.py

示例5: getpluginversioninfo

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def getpluginversioninfo(config):
    lines = []
    plugininfo = config.pluginmanager.list_plugin_distinfo()
    if plugininfo:
        lines.append("setuptools registered plugins:")
        for plugin, dist in plugininfo:
            loc = getattr(plugin, "__file__", repr(plugin))
            content = "{}-{} at {}".format(dist.project_name, dist.version, loc)
            lines.append("  " + content)
    return lines 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:12,代碼來源:helpconfig.py

示例6: test_filename

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_filename():
    x = filename_for_module

    assert x("bogus", "bogus") == "bogus"

    assert x("os", os.__file__) == "os.py"
    assert x("pytest", pytest.__file__) == "pytest.py"

    import sentry_sdk.utils

    assert x("sentry_sdk.utils", sentry_sdk.utils.__file__) == "sentry_sdk/utils.py" 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:13,代碼來源:test_general.py

示例7: showversion

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def showversion(config: Config) -> None:
    if config.option.version > 1:
        sys.stderr.write(
            "This is pytest version {}, imported from {}\n".format(
                pytest.__version__, pytest.__file__
            )
        )
        plugininfo = getpluginversioninfo(config)
        if plugininfo:
            for line in plugininfo:
                sys.stderr.write(line + "\n")
    else:
        sys.stderr.write("pytest {}\n".format(pytest.__version__)) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:15,代碼來源:helpconfig.py

示例8: getpluginversioninfo

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def getpluginversioninfo(config: Config) -> List[str]:
    lines = []
    plugininfo = config.pluginmanager.list_plugin_distinfo()
    if plugininfo:
        lines.append("setuptools registered plugins:")
        for plugin, dist in plugininfo:
            loc = getattr(plugin, "__file__", repr(plugin))
            content = "{}-{} at {}".format(dist.project_name, dist.version, loc)
            lines.append("  " + content)
    return lines 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:12,代碼來源:helpconfig.py

示例9: test_traceback_cut_excludepath

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_traceback_cut_excludepath(self, testdir):
        p = testdir.makepyfile("def f(): raise ValueError")
        with pytest.raises(ValueError) as excinfo:
            p.pyimport().f()
        basedir = py.path.local(pytest.__file__).dirpath()
        newtraceback = excinfo.traceback.cut(excludepath=basedir)
        for x in newtraceback:
            if hasattr(x, "path"):
                assert not py.path.local(x.path).relto(basedir)
        assert newtraceback[-1].frame.code.path == p 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:12,代碼來源:test_excinfo.py

示例10: test_repr_tracebackentry_lines

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_repr_tracebackentry_lines(self, importasmod) -> None:
        mod = importasmod(
            """
            def func1():
                raise ValueError("hello\\nworld")
        """
        )
        excinfo = pytest.raises(ValueError, mod.func1)
        excinfo.traceback = excinfo.traceback.filter()
        p = FormattedExcinfo()
        reprtb = p.repr_traceback_entry(excinfo.traceback[-1])

        # test as intermittent entry
        lines = reprtb.lines
        assert lines[0] == "    def func1():"
        assert lines[1] == '>       raise ValueError("hello\\nworld")'

        # test as last entry
        p = FormattedExcinfo(showlocals=True)
        repr_entry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
        lines = repr_entry.lines
        assert lines[0] == "    def func1():"
        assert lines[1] == '>       raise ValueError("hello\\nworld")'
        assert lines[2] == "E       ValueError: hello"
        assert lines[3] == "E       world"
        assert not lines[4:]

        loc = repr_entry.reprfileloc
        assert loc is not None
        assert loc.path == mod.__file__
        assert loc.lineno == 3
        # assert loc.message == "ValueError: hello" 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:34,代碼來源:test_excinfo.py

示例11: test_toterminal_long_filenames

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_toterminal_long_filenames(self, importasmod, tw_mock):
        mod = importasmod(
            """
            def f():
                raise ValueError()
        """
        )
        excinfo = pytest.raises(ValueError, mod.f)
        path = py.path.local(mod.__file__)
        old = path.dirpath().chdir()
        try:
            repr = excinfo.getrepr(abspath=False)
            repr.toterminal(tw_mock)
            x = py.path.local().bestrelpath(path)
            if len(x) < len(str(path)):
                msg = tw_mock.get_write_msg(-2)
                assert msg == "mod.py"
                assert tw_mock.lines[-1] == ":3: ValueError"

            repr = excinfo.getrepr(abspath=True)
            repr.toterminal(tw_mock)
            msg = tw_mock.get_write_msg(-2)
            assert msg == path
            line = tw_mock.lines[-1]
            assert line == ":3: ValueError"
        finally:
            old.chdir() 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:29,代碼來源:test_excinfo.py

示例12: run_tests_with_coverage

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def run_tests_with_coverage(tracer, *runner_args):
    """Run tests, but with coverage."""
    # Need to define this early enough that the first import of env.py sees it.
    os.environ['COVERAGE_TESTING'] = "True"
    os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
    os.environ['COVERAGE_HOME'] = os.getcwd()

    # Create the .pth file that will let us measure coverage in sub-processes.
    # The .pth file seems to have to be alphabetically after easy-install.pth
    # or the sys.path entries aren't created right?
    pth_dir = os.path.dirname(pytest.__file__)
    pth_path = os.path.join(pth_dir, "zzz_metacov.pth")
    with open(pth_path, "w") as pth_file:
        pth_file.write("import coverage; coverage.process_startup()\n")

    # Make names for the data files that keep all the test runs distinct.
    impl = platform.python_implementation().lower()
    version = "%s%s" % sys.version_info[:2]
    if '__pypy__' in sys.builtin_module_names:
        version += "_%s%s" % sys.pypy_version_info[:2]
    suffix = "%s%s_%s_%s" % (impl, version, tracer, platform.platform())

    os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov."+suffix)

    import coverage
    cov = coverage.Coverage(config_file="metacov.ini", data_suffix=False)
    cov._warn_unimported_source = False
    cov._warn_preimported_source = False
    cov.start()

    try:
        # Re-import coverage to get it coverage tested!  I don't understand all
        # the mechanics here, but if I don't carry over the imported modules
        # (in covmods), then things go haywire (os == None, eventually).
        covmods = {}
        covdir = os.path.split(coverage.__file__)[0]
        # We have to make a list since we'll be deleting in the loop.
        modules = list(sys.modules.items())
        for name, mod in modules:
            if name.startswith('coverage'):
                if getattr(mod, '__file__', "??").startswith(covdir):
                    covmods[name] = mod
                    del sys.modules[name]
        import coverage                         # pylint: disable=reimported
        sys.modules.update(covmods)

        # Run tests, with the arguments from our command line.
        status = run_tests(tracer, *runner_args)

    finally:
        cov.stop()
        os.remove(pth_path)

    cov.combine()
    cov.save()

    return status 
開發者ID:nedbat,項目名稱:coveragepy-bbmirror,代碼行數:59,代碼來源:igor.py

示例13: test_repr_traceback_with_invalid_cwd

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def test_repr_traceback_with_invalid_cwd(self, importasmod, monkeypatch) -> None:
        mod = importasmod(
            """
            def f(x):
                raise ValueError(x)
            def entry():
                f(0)
        """
        )
        excinfo = pytest.raises(ValueError, mod.entry)

        p = FormattedExcinfo(abspath=False)

        raised = 0

        orig_getcwd = os.getcwd

        def raiseos():
            nonlocal raised
            upframe = sys._getframe().f_back
            assert upframe is not None
            if upframe.f_code.co_name == "checked_call":
                # Only raise with expected calls, but not via e.g. inspect for
                # py38-windows.
                raised += 1
                raise OSError(2, "custom_oserror")
            return orig_getcwd()

        monkeypatch.setattr(os, "getcwd", raiseos)
        assert p._makepath(__file__) == __file__
        assert raised == 1
        repr_tb = p.repr_traceback(excinfo)

        matcher = LineMatcher(str(repr_tb).splitlines())
        matcher.fnmatch_lines(
            [
                "def entry():",
                ">       f(0)",
                "",
                "{}:5: ".format(mod.__file__),
                "_ _ *",
                "",
                "    def f(x):",
                ">       raise ValueError(x)",
                "E       ValueError: 0",
                "",
                "{}:3: ValueError".format(mod.__file__),
            ]
        )
        assert raised == 3 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:52,代碼來源:test_excinfo.py

示例14: run_tests_with_coverage

# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import __file__ [as 別名]
def run_tests_with_coverage(tracer, *runner_args):
    """Run tests, but with coverage."""
    # Need to define this early enough that the first import of env.py sees it.
    os.environ['COVERAGE_TESTING'] = "True"
    os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
    os.environ['COVERAGE_HOME'] = os.getcwd()

    # Create the .pth file that will let us measure coverage in sub-processes.
    # The .pth file seems to have to be alphabetically after easy-install.pth
    # or the sys.path entries aren't created right?
    # There's an entry in "make clean" to get rid of this file.
    pth_dir = os.path.dirname(pytest.__file__)
    pth_path = os.path.join(pth_dir, "zzz_metacov.pth")
    with open(pth_path, "w") as pth_file:
        pth_file.write("import coverage; coverage.process_startup()\n")

    suffix = "%s_%s" % (make_env_id(tracer), platform.platform())
    os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov."+suffix)

    import coverage
    cov = coverage.Coverage(config_file="metacov.ini")
    cov._warn_unimported_source = False
    cov._warn_preimported_source = False
    cov.start()

    try:
        # Re-import coverage to get it coverage tested!  I don't understand all
        # the mechanics here, but if I don't carry over the imported modules
        # (in covmods), then things go haywire (os == None, eventually).
        covmods = {}
        covdir = os.path.split(coverage.__file__)[0]
        # We have to make a list since we'll be deleting in the loop.
        modules = list(sys.modules.items())
        for name, mod in modules:
            if name.startswith('coverage'):
                if getattr(mod, '__file__', "??").startswith(covdir):
                    covmods[name] = mod
                    del sys.modules[name]
        import coverage                         # pylint: disable=reimported
        sys.modules.update(covmods)

        # Run tests, with the arguments from our command line.
        status = run_tests(tracer, *runner_args)

    finally:
        cov.stop()
        os.remove(pth_path)

    cov.combine()
    cov.save()

    return status 
開發者ID:nedbat,項目名稱:coveragepy,代碼行數:54,代碼來源:igor.py


注:本文中的pytest.__file__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。