目次

前のトピックへ

skip と xfail: 成功しないテストを扱う

次のトピックへ

非推奨の警告やその他の警告のアサート

属性をもつテスト関数のマーク

pytest.mark ヘルパーを使って、テスト関数にメタデータを簡単に設定できます。組み込みのマーカーを紹介します:

  • skipif: 特定の条件を満たした場合にテスト関数をスキップ
  • xfail: 特定の条件を満たした場合に “失敗を期待”
  • parametrize: 同じテスト関数に対して複数回の呼び出しを実行

カスタムマーカーを作成する、または全体のテストクラスやモジュールにマーカーを適用するのは簡単です。ドキュメントでもある カスタムマーカーを使う のサンプルを参照してください。

マーカー関連オブジェクトの API リファレンス

class _pytest.mark.MarkGenerator[source]

Factory for MarkDecorator objects - exposed as a py.test.mark singleton instance. Example:

import py
@py.test.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 = py.test.mark.NAME              # simple MarkDecorator
mark2 = py.test.mark.NAME(name1=value) # parametrized MarkDecorator

and can then be applied as decorators to test functions:

@mark2
def test_function():
    pass
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

positional argument list, empty if none specified

kwargs

keyword argument dictionary, empty if nothing specified

name

name of attribute