2016-05-26 6 views
0

私は複数のアプリを持つDjangoプロジェクトを持っています。各アプリにはユニットテストのセットがあります。私はテストランナーとしてpytestを使用しています。私たちは統合テストの作成を開始したいと思っています。私は、命名規則を維持するための方法があるかどうかと、pytestの自動検出が可能かどうかは疑問に思っていました。最も直感的な解決策は、テストメソッドのデコレータや、TestCaseクラス(JUnitのCategoryのようなもの)です。
のようなもの:Pythonでunittests integrationテストを実行しています

@testtype('unittest') 
def test_my_test(self): 
    # do some testing 

@testtype('integration') 
def test_my_integration_test(self): 
    # do some integration testing 

、その後、私の好きなテストを実行できます。

py.test --type=integration 
py.test --type=unittest 

はそのようなことはありますか?
もし私が考えることができる唯一の他の解決策は、djangoコマンドを追加し、 "手動で" testsuiteをビルドしpytestで実行することです。私はこのオプションを使用しないことをお勧めします。私を助けることができる他の解決策はありますか?
ありがとう

答えて

2

mark test functionsです。

import pytest 

@pytest.mark.unittest 
def test_my_test(self): 
    # do some testing 

@pytest.mark.integration 
def test_my_integration_test(self): 
    # do some integration testing 

これらのカスタムマーカーは、pytest.iniファイルにregisteredである必要があります。

次にマークテスト

py.test -v -m unittest 
を実行するために -mフラグを使用
関連する問題