diff --git a/python/helpers/python-skeletons/pytest/__init__.py b/python/helpers/python-skeletons/pytest/__init__.py index bc59c4a72f63..f57b3ee10801 100644 --- a/python/helpers/python-skeletons/pytest/__init__.py +++ b/python/helpers/python-skeletons/pytest/__init__.py @@ -66,6 +66,113 @@ class collect: def set_trace(): """ invoke PDB set_trace debugging, dropping any IO capturing. """ +# _pytest.mark +class mark: + + def __getattr__(self, item): + """ + This class may have any attribute, so this method should exist + """ + pass + + @staticmethod + def skipif(condition, reason=None): + """skip the given test function if eval(condition) results in a True + value. + + Optionally specify a reason for better reporting. + + Evaluation happens within the module global context. + Example: ``skipif('sys.platform == "win32"')`` skips the test if + we are on the win32 platform. + + see http://doc.pytest.org/en/latest/skipping.html + """ + + @staticmethod + def skip(reason=None): + """skip the given test function, optionally specify a reason for better reporting. + + see http://doc.pytest.org/en/latest/skipping.html + """ + + @staticmethod + def xfail(condition=None, reason=None, raises=None, run=True, strict=False): + """mark the the test function as an expected failure if eval(condition) + has a True value. + + Optionally specify a reason for better reporting and run=False if + you don't even want to execute the test function. + + See http://doc.pytest.org/en/latest/skipping.html + """ + + @staticmethod + def parametrize(argnames, argvalues, indirect=False, ids=None, scope=None): + """ Add new invocations to the underlying test function using the list + of argvalues for the given argnames. Parametrization is performed + during the collection phase. If you need to setup expensive resources + see about setting indirect to do it rather at test setup time. + + :arg argnames: a comma-separated string denoting one or more argument + names, or a list/tuple of argument strings. + + :arg argvalues: The list of argvalues determines how often a + test is invoked with different argument values. If only one + argname was specified argvalues is a list of values. If N + argnames were specified, argvalues must be a list of N-tuples, + where each tuple-element specifies a value for its respective + argname. + + :arg indirect: The list of argnames or boolean. A list of arguments' + names (subset of argnames). If True the list contains all names from + the argnames. Each argvalue corresponding to an argname in this list will + be passed as request.param to its respective argname fixture + function so that it can perform more expensive setups during the + setup phase of a test rather than at collection time. + + :arg ids: list of string ids, or a callable. + If strings, each is corresponding to the argvalues so that they are + part of the test id. If None is given as id of specific test, the + automatically generated id for that argument will be used. + If callable, it should take one argument (a single argvalue) and return + a string or return None. If None, the automatically generated id for that + argument will be used. + If no ids are provided they will be generated automatically from + the argvalues. + + :arg scope: if specified it denotes the scope of the parameters. + The scope is used for grouping tests by parameter instances. + It will also override any fixture-function defined scope, allowing + to set a dynamic scope using test context or configuration. + """ + + @staticmethod + def usefixtures(*fixturenames): + """mark tests as needing all of the specified fixtures. + + see http://doc.pytest.org/en/latest/fixture.html#usefixtures + """ + + @staticmethod + def tryfirst(f): + """mark a hook implementation function such that the plugin machinery + will try to call it first/as early as possible. + """ + + @staticmethod + def trylast(f): + """mark a hook implementation function such that the plugin machinery + will try to call it last/as late as possible. + """ + + @staticmethod + def hookwrapper(f): + """A hook wrapper is a generator function which yields exactly once. + When pytest invokes hooks it first executes hook wrappers and passes + the same arguments as to the regular hooks. + """ + # _pytest.python def raises(ExpectedException, *args, **kwargs):