16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pytestで1ファイル/1テストだけ実行したい(他よく使うオプション)

Last updated at Posted at 2019-07-15

pytest実行時に便利なオプションを書いた備忘録です。

前提条件

例で出てくるプロジェクトのイメージ

pj_root(カレントディレクトリ)
  ├..
  └tests
    ├..
    └test_example.py

例で登場するtest_example.pyのイメージ

test_example.py
import unittest


class TestExample(unittest.TestCase):

    def test_example_ok_pattern(self):
        actual = True
        expected = True
        assert actual == expected

1ファイル/1テストだけ実行したい

1ファイルだけ実行する

pytest (path)

# 例
pytest tests/test_exapmle.py

1テストだけ実行する

pytest (path)::(TestClass)::(test_method)
pytest (path)::(test_method)

# 例
pytest tests/test_exapmle.py::TestExample::test_example_ok_pattern

その他、よく使うオプション

最後にコケたテストだけ実行する

pytest --lf

テストが1つでもコケたらそこでテスト実行を止める

pytest -x

テストがコケた時に結果を詳細に表示する

pytest -vv
16
8
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
16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?