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

  • EmbarkToHeaven

    EmbarkToHeav

    3 EYLÜL 2007
  • Kim Barbin

    Kim Barbin

    3 Mayıs 2012
  • Kanál používateľa McsFuego

    Kanál použ

    12 EKİM 2011