Python インタープリターの対話モードから次のように入力すると:
import pytest
help(pytest)
グローバルに利用できるヘルパー機能の概要を把握できます。
pytest: unit and functional testing with Python.
return exit code, after performing an in-process test run.
パラメタ: |
|
---|
explicitely fail an currently-executing test with the given Message.
パラメタ: | pytrace – if false the msg represents the full failure information and no python traceback will be reported. |
---|
skip an executing test with the given message. Note: it’s usually better to use the py.test.mark.skipif marker to declare a test to be skipped under certain conditions like mismatching platforms or dependencies. See the pytest_skipping plugin for details.
exit testing process as if KeyboardInterrupt was triggered.
return imported module if it has a higher __version__ than the optionally specified ‘minversion’ - otherwise call py.test.skip() with a message detailing the mismatch.
(return a) decorator to mark a fixture factory function.
This decorator can be used (with or or without parameters) to define a fixture function. The name of the fixture function can later be referenced to cause its invocation ahead of running tests: test modules or classes can use the pytest.mark.usefixtures(fixturename) marker. Test functions can directly use fixture names as input arguments in which case the fixture instance returned from the fixture function will be injected.
パラメタ: |
|
---|
assert that a code block/function call raises @ExpectedException and raise a failure exception otherwise.
If using Python 2.5 or above, you may use this function as a context manager:
>>> with raises(ZeroDivisionError):
... 1/0
Or you can specify a callable by passing a to-be-called lambda:
>>> raises(ZeroDivisionError, lambda: 1/0)
<ExceptionInfo ...>
or you can specify an arbitrary callable with arguments:
>>> def f(x): return 1/x
...
>>> raises(ZeroDivisionError, f, 0)
<ExceptionInfo ...>
>>> raises(ZeroDivisionError, f, x=0)
<ExceptionInfo ...>
A third possibility is to use a string to be executed:
>>> raises(ZeroDivisionError, "f(0)")
<ExceptionInfo ...>
xfail an executing test or setup functions with the given reason.
assert that calling func(*args, **kwargs) triggers a DeprecationWarning.
次のように入力して、利用できる組み込みまたはプロジェクトカスタムの 関数の引数 を確認できます。
$ py.test –fixtures====================== test session starts =======================platform linux2 – Python 2.7.1 – pytest-2.2.4collected 0 itemspytestconfigpytest の config オブジェクトとコマンドラインオプションへのアクセスcapsyssys.stdout/sys.stderr への書き込み内容を取得できるキャプチャした出力内容は (out, err) のタプルを返すcapsys.readouterr() メソッドで利用できるcapfdファイルディスクリプタ 1 と 2 へ書き込み内容を取得できるキャプチャした出力内容は (out, err) のタプルを返すcapsys.readouterr() メソッドで利用できるtmpdir基本となる一時ディレクトリ配下にサブディレクトリを作成して、テスト関数の実行毎に一意な一時ディレクトリのオブジェクトを返すこれは py.path.local のパスオブジェクトが返されるmonkeypatchオブジェクト、ディクショナリ、os.environ を変更する次のヘルパーメソッドを提供する monkeypatch オブジェクトが返されるmonkeypatch.setattr(obj, name, value, raising=True)monkeypatch.delattr(obj, name, raising=True)monkeypatch.setitem(mapping, name, value)monkeypatch.delitem(obj, name, raising=True)monkeypatch.setenv(name, value, prepend=False)monkeypatch.delenv(name, value, raising=True)monkeypatch.syspath_prepend(path)monkeypatch.chdir(path)全ての変更はテスト関数の呼び出しが終わった後で元に戻りますraising パラメーターは、セット/削除の操作対象がないときにKeyError や AttributeError を発生させるかどうかを決めますrecwarn次のメソッドを提供する WarningsRecorder インスタンスを返す* pop(category=None): category に一致する最後の警告を返す* clear(): 警告のリストを削除する参照してください======================== in 0.00 seconds ========================