matkapi / postpy2

Postman collection runner library for python
Other
35 stars 15 forks source link

Form Data files are not closed properly [BUG] #4

Closed elsamuray7 closed 2 years ago

elsamuray7 commented 3 years ago

When one sends the same request multiple times, which includes a form data file, and uses pdb to debug the application, a warning is displayed that states that the application accesses a file that is already open.

If the client side application that uses postpy2 is not just a unit test but a long running application, not closing the file can cause problems. Hence, the file should be just opened once to read its content into memory and then be closed. Therefore, one could use io.BytesIO which does not have to be closed.

io.BytesIO close method simply sets a boolean value self.closed to True (see the source code) :

def close(self):
    self.closed = True

Thus, it makes the code safer to not cause any problems.

elsamuray7 commented 3 years ago

My pull request should have fixed the issue.