Changeset 1822:588dd642fb25


Ignore:
Timestamp:
Jun 30, 2019, 4:15:52 PM (8 weeks ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Create `sock` per instance, not per class

The mock socket object is used to verify in tests whether the socket's
`gettimeout` and `settimeout` methods are called. Defining the mock
object at the class level causes all `ScriptedSession` objects to
share the mock. Therefore, if multiple tests call `sock.gettimeout`
or `sock.settimeout` they interfere with each other.

I noticed the problem when running `test_host.py` alone with `pytest
test/test_host.py` succeeded, but running all fast tests with
`make test` failed in
`test.test_host.TestUploadAndDownload.test_download` because of a
test on the `sock` attribute.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/scripted_session.py

    r1820 r1822  
    105105    def __init__(self, script):
    106106        self.script = script
     107        # `File.close` accesses the session `sock` object to set and reset the
     108        # timeout. `sock` itself is never _called_ though, so it doesn't make
     109        # sense to create a `sock` _call_.
     110        self.sock = unittest.mock.Mock(name="socket_attribute")
    107111        # Index into `script`, the list of `Call` objects
    108112        self._call_index = 0
     
    144148    # `ftplib.FTP` methods that shouldn't be executed with the default
    145149    # processing in `__getattr__`
    146 
    147     # `File.close` accesses the session `sock` object to set and reset the
    148     # timeout. `sock` itself is never _called_ though, so it doesn't make sense
    149     # to create a `sock` _call_.
    150     sock = unittest.mock.Mock(name="socket_attribute")
    151150
    152151    def dir(self, path, callback):
Note: See TracChangeset for help on using the changeset viewer.