fakefs / fakefs

A fake filesystem. Use it in your tests.
MIT License
1.04k stars 188 forks source link

Using requests with fakefs #469

Closed davidorme closed 2 years ago

davidorme commented 2 years ago

Hi,

Just in case anyone else comes across this edge case, we were using the requests package within a set of tests using fakefs. That gave us a consistent failure:

====================================================================================== short test summary info ======================================================================================
FAILED test/test_requests.py::test_requests_fake - OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /xxx/site-packages/cert...
==================================================================================== 1 failed, 1 passed in 2.33s ====================================================================================

The issue here is that requests relies on the certifi package for HTTPS certificate chains - and the underlying certificate bundle is only loaded when required, not when the certifi package is imported.

Once we figured out the problem, the solution is pretty simple: in the setup of the fake filesystem (probably as a fixture in conftest.py)

import certifi
fs.add_real_file(certifi.where())
grosser commented 2 years ago

this is the ruby library not python

davidorme commented 2 years ago

Ack, really sorry