SORU
17 Kasım 2008, PAZARTESİ


Nasıl bir mock/stub python urllib modülü olabilir

Harici bir sunucuya urllib kullanarak bir sayfa sorgu gereken bir fonksiyonu test etmek istiyorum.(bunu da kullanır urllib.urlopen urlencode). Sunucu çalışmıyor olabilir, sayfayı değiştirebilir; bir test için güvenemem.

Ne urllib denetlemek için en iyi yoldur.urlopen verir?

CEVAP
6 Mart 2010, CUMARTESİ


Mock's yama dekoratör kullanıyorum:

from mock import patch

[...]

@patch('urllib.urlopen')
def test_foo(self, urlopen_mock):
    urlopen_mock.return_value = MyUrlOpenMock()

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dopelives

    Dopelives

    30 Temmuz 2009
  • New Challenger - Game Reviews

    New Challeng

    20 Temmuz 2006
  • Semantic Mastery

    Semantic Mas

    30 EKİM 2013