Hi,
This an odd use case failure and not a bug but I just wanted to record it in case anyone else comes it.
We are using the requests package within a set of tests using pyfakefs. 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 uses the certifi package for HTTPS certificate chains - and the underlying certificate bundle is only loaded from file when required, not when certifi is imported. So, tests that use requests from HTTPS sites fail.
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) you need to import certifi and then add the real certificate bundle to fs.
import certifi
fs.add_real_file(certifi.where())
I don't think any changes are needed - unless there is something that allows fs to know about site package locations automatically - but it took us a while to figure out what was wrong.
Hi,
This an odd use case failure and not a bug but I just wanted to record it in case anyone else comes it.
We are using the
requestspackage within a set of tests usingpyfakefs. That gave us a consistent failure:The issue here is that
requestsuses thecertifipackage for HTTPS certificate chains - and the underlying certificate bundle is only loaded from file when required, not whencertifiis imported. So, tests that use requests from HTTPS sites fail.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) you need to import
certifiand then add the real certificate bundle tofs.I don't think any changes are needed - unless there is something that allows
fsto know about site package locations automatically - but it took us a while to figure out what was wrong.