Python pytest.__file__() Examples
The following are 16
code examples of pytest.__file__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pytest
, or try the search function
.
Example #1
Source File: helpconfig.py From python-netsurv with MIT License | 6 votes |
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
Example #2
Source File: helpconfig.py From pytest with MIT License | 6 votes |
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
Example #3
Source File: test_entrypoints.py From dephell with MIT License | 5 votes |
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'}
Example #4
Source File: helpconfig.py From python-netsurv with MIT License | 5 votes |
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")
Example #5
Source File: helpconfig.py From python-netsurv with MIT License | 5 votes |
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
Example #6
Source File: helpconfig.py From python-netsurv with MIT License | 5 votes |
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")
Example #7
Source File: helpconfig.py From python-netsurv with MIT License | 5 votes |
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
Example #8
Source File: test_general.py From sentry-python with BSD 2-Clause "Simplified" License | 5 votes |
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"
Example #9
Source File: helpconfig.py From pytest with MIT License | 5 votes |
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__))
Example #10
Source File: helpconfig.py From pytest with MIT License | 5 votes |
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
Example #11
Source File: test_excinfo.py From pytest with MIT License | 5 votes |
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
Example #12
Source File: test_excinfo.py From pytest with MIT License | 5 votes |
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"
Example #13
Source File: test_excinfo.py From pytest with MIT License | 5 votes |
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()
Example #14
Source File: igor.py From coveragepy-bbmirror with Apache License 2.0 | 4 votes |
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
Example #15
Source File: test_excinfo.py From pytest with MIT License | 4 votes |
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
Example #16
Source File: igor.py From coveragepy with Apache License 2.0 | 4 votes |
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