PyDev ile pytest birim testleri çalıştırırken bir sorunum var. Bir modül testini bir modül paylaşımlı fikstürle ve son testten sonra heyecanlandırılması gereken bir finalizer ile çalıştırmaya çalışıyorum. Ancak birim testini pyDev'de çalıştırırken aynı örneği kullanmaz, bunun yerine iki farklı örnek oluşturur. Örnek, konsolda veya pydev içindeki bir komut dosyasından başlatıldığında düzgün çalışıyor.PyDev modülünün paylaşılan fikstürle çalışan pytest birim testi başarısız oldu
Ben platformu Python 2.7.3, pytest-2.3.4, Pydev 2.7.3.2013031601, Win7 üzerinde Eclipse 4.2 kullanıyorum.
ben Pydev gelen http://pytest.org/latest/fixture.htmlçıkış dan örnek çalıştı geçerli:
============================= 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>
konsol çıktısı: beklenen davranış olduğunu
============================= 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>
. Neyi yanlış yapıyorum??
# 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
ile komut dosyasından testi çalışıyor:
import pytest,os
os.chdir("[path_to_tests]/tests") #your file location
pytest.main(['-s', 'test_smtplib.py'])
Herhangi önerileri test_smtplib.py içinde
import pytest
import smtplib
@pytest.fixture(scope="module")
def smtp():
return smtplib.SMTP("merlinux.eu")
Test kodu:
kullanılan kod conftest.py olduğunu ve yardımlarınız için çok teşekkürler!
size Pydev IDE ** py.test ** Test atlet kullanmak yapılandırmak mü (* Pencere -> Tercihler -> Pydev -> pyunit -> Test Aracı *)? –
Evet, PyDev Test Runner seçildi. – MBaumann
Hayır, * PyDev Test Runner * değil, aynı zamanda *** Py.test ** Test Runner * 'ı seçebilme olanağına sahip olmalısınız -> bak: http://up.picr.de/14054750vh.jpg –