属性をもつテスト関数のマーク
pytest.mark ヘルパーを使って、テスト関数にメタデータを簡単に設定できます。組み込みのマーカーを紹介します:
カスタムマーカーを作成する、または全体のテストクラスやモジュールにマーカーを適用するのは簡単です。ドキュメントでもある カスタムマーカーを使う のサンプルを参照してください。
マーカー関連オブジェクトの API リファレンス
-
class _pytest.mark.MarkGenerator[source]
Factory for MarkDecorator objects - exposed as
a pytest.mark singleton instance. Example:
import py
@pytest.mark.slowtest
def test_function():
pass
will set a ‘slowtest’ MarkInfo object
on the test_function object.
-
class _pytest.mark.MarkDecorator(name, args=None, kwargs=None)[source]
A decorator for test functions and test classes. When applied
it will create MarkInfo objects which may be
retrieved by hooks as item keywords.
MarkDecorator instances are often created like this:
mark1 = pytest.mark.NAME # simple MarkDecorator
mark2 = pytest.mark.NAME(name1=value) # parametrized MarkDecorator
and can then be applied as decorators to test functions:
@mark2
def test_function():
pass
- When a MarkDecorator instance is called it does the following:
- If called with a single class as its only positional argument and no
additional keyword arguments, it attaches itself to the class so it
gets applied automatically to all test cases found in that class.
- If called with a single function as its only positional argument and
no additional keyword arguments, it attaches a MarkInfo object to the
function, containing all the arguments already stored internally in
the MarkDecorator.
- When called in any other case, it performs a ‘fake construction’ call,
i.e. it returns a new MarkDecorator instance with the original
MarkDecorator’s content updated with the arguments passed to this
call.
Note: The rules above prevent MarkDecorator objects from storing only a
single function or class reference as their positional argument with no
additional keyword or positional arguments.
-
class _pytest.mark.MarkInfo(name, args, kwargs)[source]
Marking object created by MarkDecorator instances.
-
add(args, kwargs)[source]
add a MarkInfo with the given args and kwargs.
-
args = None
positional argument list, empty if none specified
-
kwargs = None
keyword argument dictionary, empty if nothing specified
-
name = None
name of attribute