Using requests within tests using pyfakefs #675
davidorme
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks for that, good find! No, there isn't a reliable way to know about site package locations in |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
This an odd use case failure and not a bug but I just wanted to record it in case anyone else comes across it.
We are using the
requests
package within a set of tests usingpyfakefs
. That gave us a consistent failure:The issue here is that
requests
uses thecertifi
package for HTTPS certificate chains - and the underlying certificate bundle is only loaded from file when required, not whencertifi
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 tofs
.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.Beta Was this translation helpful? Give feedback.
All reactions