pyDevでpytestユニットテストを実行する際に問題が発生しました。私は、最後のテストの後に実行するモジュール共有フィクスチャとファイナライザでユニットテストを実行しようとします。 しかし、pyDevで単体テストを実行すると、同じインスタンスは使用されず、代わりに2つの異なるインスタンスが作成されます。この例は、コンソールやpydev内のスクリプトから起動したときに正常に動作しています。モジュール共有フィクスチャでpytestユニットテストを実行するPyDevが失敗する
私はプラットフォームPython 2.7.3、pytest-2.3.4、pyDev 2.7.3.2013031601、Eclipse 4.2 on Win7を使用しています。
私はhttp://pytest.org/latest/fixture.html
出力からPyDevはからの例を試してみましたが、次のとおりです。
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.4
__________________________________ test_ehlo ___________________________________
smtp = <smtplib.SMTP instance at 0x027F9080>
__________________________________ test_noop ___________________________________
smtp = <smtplib.SMTP instance at 0x027FF3C8>
コンソール出力は次のようになります。
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.4
__________________________________ test_ehlo ___________________________________
smtp = <smtplib.SMTP instance at 0x01E51288>
__________________________________ test_noop ___________________________________
smtp = <smtplib.SMTP instance at 0x01E51288>
予期された動作です。私は何を間違えているのですか?
# content of test_module.py
def test_ehlo(smtp):
response = smtp.ehlo()
assert response[0] == 250
assert "merlinux" in response[1]
assert 0 # for demo purposes
def test_noop(smtp):
response = smtp.noop()
assert response[0] == 250
assert 0 # for demo purposes
でスクリプトからテストを実行する:
import pytest,os
os.chdir("[path_to_tests]/tests") #your file location
pytest.main(['-s', 'test_smtplib.py'])
任意の提案test_smtplib.pyで
import pytest
import smtplib
@pytest.fixture(scope="module")
def smtp():
return smtplib.SMTP("merlinux.eu")
テストコード:
使用されるコードはconftest.pyですあなたの助けをたくさんありがとう!
** py.test **テストランナー(*ウィンドウ - >環境設定 - > PyDev - > PyUnit - >テストランナー*)を使用するようにPyDev IDEを構成しましたか? –
はい、PyDevテストランナーが選択されています。 – MBaumann
いいえ、* PyDev Test Runner *ではなく、Py.test ** Test Runner * - > look:http://up.picr.de/14054750vh.jpg –