mindflayer / python-mocket

a socket mock framework - for all kinds of socket animals, web-clients included
BSD 3-Clause "New" or "Revised" License
284 stars 43 forks source link

Can it mock socket errors? #112

Closed dimaqq closed 4 years ago

dimaqq commented 4 years ago

It would be awesome if mocket could also mock all kinds of socket errors on demand. I'd love to use this library for negative tests as well as regular tests...

mindflayer commented 4 years ago

I am studying a solution. I'll let you know soon if that can be done without breaking anything.

mindflayer commented 4 years ago

Hi @dimaqq, after months I spent some more time on it and I made it in a simple and effective way. I am solving a few Python 2 issues and it'll be ready to be shipped.

mindflayer commented 4 years ago

It's as simple as:

    @mocketize
    def test_raise_exception(self):
        url = "http://github.com/fluidicon.png"
        Entry.single_register(Entry.GET, url, exception=socket.error())
        with self.assertRaises(requests.exceptions.ConnectionError):
            requests.get(url)
mindflayer commented 4 years ago

Of course after a pip install mocket==3.9.2. :package: https://pypi.org/project/mocket/3.9.2/