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 pytest.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 at least “minversion” as its __version__ attribute. If no minversion is specified the a skip is only triggered if the module can not be imported. Note that version comparison only works with simple version strings like “1.2.3” but not “1.2.3.dev1” or others.
(return a) decorator to mark a yield-fixture factory function (EXPERIMENTAL).
This takes the same arguments as pytest.fixture() but expects a fixture function to use a yield instead of a return statement to provide a fixture. See http://pytest.org/en/latest/yieldfixture.html for more info.
(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.
This helper produces a py.code.ExceptionInfo() object.
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 ...>
Similar to caught exception objects in Python, explicitly clearing local references to returned py.code.ExceptionInfo objects can help the Python interpreter speed up its garbage collection.
Clearing those references breaks a reference cycle (ExceptionInfo –> caught exception –> frame stack raising the exception –> current frame stack –> local variables –> ExceptionInfo) which makes Python keep all objects referenced from that cycle (including all local variables in the current frame) alive until the next cyclic garbage collection run. See the official Python try statement documentation for more detailed information.
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 ========================