LoginSignup
2
0

More than 1 year has passed since last update.

pytest conftest.pyにおけるHookの実行順序の備忘録

Posted at

経緯

conftest.py内に記述するHookの実行順序がよく分からなかったので、各functionの定義とprint文を記述し、テストが1個のファイルに対してpytestを実行して、実行順序を確認してみました。

関連ドキュメント

pytestのバージョン

  • 7.1.2

出力結果の確認

テスト セッション開始前

  • pytest_addhooks
  • pytest_addoption
  • pytest_plugin_registered (複数回)
  • pytest_warning_recorded
  • pytest_cmdline_preparse
    ← 警告が出力された。非推奨で将来削除されるので、代わりにpytest_load_initial_conftestsを使えとのこと。
    ただ、pytest_load_initial_conftestsは別途記述しているにも関わらず、出力されていない。
  • pytest_cmdline_main
  • pytest_plugin_registered (複数回)
  • pytest_configure
  • pytest_plugin_registered (複数回)
  • pytest_sessionstart
  • pytest_plugin_registered

テスト セッション開始後

~==== test session starts ===~の出力で区切られる。

  • pytest_report_header

  • pytest_collection

  • 以下のセットが3回

    • pytest_ignore_collect
    • pytest_collect_file
    • pytest_pycollect_makemodule
  • 以下のセットが2回

    • pytest_collectstart
    • pytest_make_collect_report
    • pytest_pycollect_makeitem (1回目は複数回)
  • pytest_itemcollected

  • pytest_collectreport (2回)

  • pytest_collection_modifyitems

collected 1 itemが出力された。

  • pytest_report_collectionfinish
  • pytest_collection_finish
  • pytest_runtestloop
  • pytest_runtest_protocol

テスト対象ファイル.pyが出力された。

  • pytest_runtest_logstart
  • pytest_runtest_setup
  • pytest_runtest_makereport
  • pytest_report_teststatus
  • pytest_runtest_logreport
  • pytest_runtest_call
  • pytest_pyfunc_call
  • pytest_runtest_makereport
  • pytest_report_teststatus

.が出力された。

  • pytest_runtest_logreport
  • pytest_runtest_teardown
  • pytest_runtest_makereport
  • pytest_report_teststatus
  • pytest_runtest_logreport
  • pytest_runtest_logfinish
  • pytest_sessionfinish

~=== warnings summary ===~の出力で区切られる。

警告内容の出力

  • pytest_terminal_summary

~=== 1 passed, 1 warning in 0.03s ===~の出力で区切られる。

  • pytest_unconfigure

(終了)

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0