Python pytest.main() Examples
The following are 30
code examples of pytest.main().
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
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: pytester.py From python-netsurv with MIT License | 7 votes |
def inline_runsource(self, source, *cmdlineargs): """Run a test module in process using ``pytest.main()``. This run writes "source" into a temporary file and runs ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance for the result. :param source: the source code of the test module :param cmdlineargs: any extra command line arguments to use :return: :py:class:`HookRecorder` instance of the result """ p = self.makepyfile(source) values = list(cmdlineargs) + [p] return self.inline_run(*values)
Example #2
Source File: manage.py From comport with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test(): """Run the tests.""" import pytest exit_code = pytest.main([TEST_PATH, '-x', '--verbose']) return exit_code
Example #3
Source File: pytester.py From python-netsurv with MIT License | 6 votes |
def pytest_addoption(parser): parser.addoption( "--lsof", action="store_true", dest="lsof", default=False, help="run FD checks if lsof is available", ) parser.addoption( "--runpytest", default="inprocess", dest="runpytest", choices=("inprocess", "subprocess"), help=( "run pytest sub runs in tests using an 'inprocess' " "or 'subprocess' (python -m main) method" ), ) parser.addini( "pytester_example_dir", help="directory to take the pytester example files from" )
Example #4
Source File: setup.py From pysaxon with Creative Commons Zero v1.0 Universal | 6 votes |
def run(self): import pytest import _pytest.main # Customize messages for pytest exit codes... msg = {_pytest.main.EXIT_OK: 'OK', _pytest.main.EXIT_TESTSFAILED: 'Tests failed', _pytest.main.EXIT_INTERRUPTED: 'Interrupted', _pytest.main.EXIT_INTERNALERROR: 'Internal error', _pytest.main.EXIT_USAGEERROR: 'Usage error', _pytest.main.EXIT_NOTESTSCOLLECTED: 'No tests collected'} bldobj = self.distribution.get_command_obj('build') bldobj.run() exitcode = pytest.main(self.pytest_opts) print(msg[exitcode]) sys.exit(exitcode)
Example #5
Source File: pytester.py From python-netsurv with MIT License | 6 votes |
def pytest_addoption(parser): parser.addoption( "--lsof", action="store_true", dest="lsof", default=False, help="run FD checks if lsof is available", ) parser.addoption( "--runpytest", default="inprocess", dest="runpytest", choices=("inprocess", "subprocess"), help=( "run pytest sub runs in tests using an 'inprocess' " "or 'subprocess' (python -m main) method" ), ) parser.addini( "pytester_example_dir", help="directory to take the pytester example files from" )
Example #6
Source File: cmds.py From sea with MIT License | 6 votes |
def generate(proto_path, protos): from grpc_tools import protoc well_known_path = os.path.join(os.path.dirname(protoc.__file__), '_proto') proto_out = os.path.join(os.getcwd(), 'protos') proto_path.append(well_known_path) proto_path_args = [] for protop in proto_path: proto_path_args += ['--proto_path', protop] cmd = [ 'grpc_tools.protoc', *proto_path_args, '--python_out', proto_out, '--grpc_python_out', proto_out, *protos ] return protoc.main(cmd)
Example #7
Source File: pytester.py From python-netsurv with MIT License | 6 votes |
def inline_runsource(self, source, *cmdlineargs): """Run a test module in process using ``pytest.main()``. This run writes "source" into a temporary file and runs ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance for the result. :param source: the source code of the test module :param cmdlineargs: any extra command line arguments to use :return: :py:class:`HookRecorder` instance of the result """ p = self.makepyfile(source) values = list(cmdlineargs) + [p] return self.inline_run(*values)
Example #8
Source File: integration_tests.py From activitywatch with Mozilla Public License 2.0 | 6 votes |
def test_integration(server_process): # This is just here so that the server_process fixture is initialized pass # exit_code = pytest.main(["./aw-server/tests", "-v"]) # if exit_code != 0: # pytest.fail("Tests exited with non-zero code: " + str(exit_code))
Example #9
Source File: _tester.py From recruit with Apache License 2.0 | 6 votes |
def test(extra_args=None): try: import pytest except ImportError: raise ImportError("Need pytest>=3.0 to run tests") try: import hypothesis # noqa except ImportError: raise ImportError("Need hypothesis>=3.58 to run tests") cmd = ['--skip-slow', '--skip-network', '--skip-db'] if extra_args: if not isinstance(extra_args, list): extra_args = [extra_args] cmd = extra_args cmd += [PKG] print("running: pytest {}".format(' '.join(cmd))) sys.exit(pytest.main(cmd))
Example #10
Source File: tasks.py From nplusone with MIT License | 5 votes |
def watch(ctx): """Run tests when a file changes. Requires pytest-xdist.""" import pytest errcode = pytest.main(['-f']) sys.exit(errcode)
Example #11
Source File: solution.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #12
Source File: problem.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #13
Source File: strings.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #14
Source File: setup.py From irl-benchmark with GNU General Public License v3.0 | 5 votes |
def run_tests(self): import pytest errno = pytest.main(self.pytest_args) sys.exit(errno)
Example #15
Source File: setup.py From poetry with MIT License | 5 votes |
def run_tests(self): import pytest errno = pytest.main(self.pytest_args) sys.exit(errno) # 'setup.py publish' shortcut.
Example #16
Source File: setup.py From file-encryptor with MIT License | 5 votes |
def run_tests(self): # Import PyTest here because outside, the eggs are not loaded. import pytest import sys errno = pytest.main(self.pytest_args) sys.exit(errno)
Example #17
Source File: tasks.py From nplusone with MIT License | 5 votes |
def test(ctx): import pytest errcode = pytest.main(['tests']) sys.exit(errcode)
Example #18
Source File: solution.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__ + ' -v')
Example #19
Source File: test_all.py From idawilli with Apache License 2.0 | 5 votes |
def main(): logging.basicConfig(level=logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG) pytest.main(['--capture=sys', os.path.dirname(__file__)])
Example #20
Source File: setup.py From zulip-terminal with Apache License 2.0 | 5 votes |
def run_tests(self): import shlex import pytest errno = pytest.main(shlex.split(self.pytest_args)) sys.exit(errno)
Example #21
Source File: Length.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #22
Source File: problem.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__ + ' -v')
Example #23
Source File: weekdays.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #24
Source File: Functions.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #25
Source File: Functions.py From PythonTrainingExercises with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): return pytest.main(__file__)
Example #26
Source File: _testutils.py From lambda-packs with MIT License | 5 votes |
def __call__(self, label="fast", verbose=1, extra_argv=None, doctests=False, coverage=False, tests=None): import pytest module = sys.modules[self.module_name] module_path = os.path.abspath(module.__path__[0]) pytest_args = ['-l'] if doctests: raise ValueError("Doctests not supported") if extra_argv: pytest_args += list(extra_argv) if verbose and int(verbose) > 1: pytest_args += ["-" + "v"*(int(verbose)-1)] if coverage: pytest_args += ["--cov=" + module_path] if label == "fast": pytest_args += ["-m", "not slow"] elif label != "full": pytest_args += ["-m", label] if tests is None: tests = [self.module_name] pytest_args += ['--pyargs'] + list(tests) try: code = pytest.main(pytest_args) except SystemExit as exc: code = exc.code return (code == 0)
Example #27
Source File: setup.py From revrand with Apache License 2.0 | 5 votes |
def run_tests(self): # import here, cause outside the eggs aren't loaded import pytest exit(pytest.main(self.pytest_args))
Example #28
Source File: _tester.py From pantab with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test(): import pytest sys.exit(pytest.main([str(PKG)]))
Example #29
Source File: pytester.py From python-netsurv with MIT License | 5 votes |
def inline_genitems(self, *args): """Run ``pytest.main(['--collectonly'])`` in-process. Runs the :py:func:`pytest.main` function to run all of pytest inside the test process itself like :py:meth:`inline_run`, but returns a tuple of the collected items and a :py:class:`HookRecorder` instance. """ rec = self.inline_run("--collect-only", *args) items = [x.item for x in rec.getcalls("pytest_itemcollected")] return items, rec
Example #30
Source File: coverage_test.py From ir with Mozilla Public License 2.0 | 5 votes |
def main(): argv = ['--cov-report=term', '--cov-report=html:./coverage_report', '--cov=./src', '--cov-fail-under=30'] out = 1 try: out = pytest.main(argv) except SystemExit: pass except Exception: out = 3 return out