序文
青年最主要的任务是学习。—— 朱德
正值青年的我的任务!!!
まず、autouse引数は何ですか?
- autouseフィクスチャパラメータのパラメータの方法である;(PS:この文を書くためにこのブログだけでは文学的才能を見るために何人かの友人を防止するには順)
- 英語からautouseがアップ自動的に文字通り理解されています。
- 自動的autouseパラメータ設定後の両方の実行の範囲内でテストメソッドを作ることができます。
二、autouseアプリケーションパラメータ
- 2.1は、コードautouseパラメータを使用していません。
import pytest
@pytest.fixture()
def setUp():
print('\nsetUp')
yield
print('\ntearDown')
def testcase01(setUp):
print('exectue testcase01')
assert 1
def testcase02(setUp):
print('exectue testcase02')
assert 1
if __name__=='__main__':
pytest.main(["-s"])
- コードパラメータを使用してautouse 2.2:
import pytest
@pytest.fixture(autouse=True) #设置为True让autouse生效
def setUp():
print('\nsetUp')
yield
print('\ntearDown')
def testcase01():
print('exectue testcase01')
assert 1
def testcase02():
print('exectue testcase02')
assert 1
if __name__=='__main__':
pytest.main(["-s"])
二つの例上記の概要:
- 読者がコードの実行の過程で見つけるには、コード実行の二枚の結果が同じで、固定具は、力になってきました。
- 例2セットautouse =真、我々は、試験方法で利便性の多くをフィクスチャの名前を追加しない11ことができます。