0

I have a Pytest test using the pyfakefs fs fixture.

def test_my_unit_test(fs):

    simple_test()

It works as expected and simple tests run with the fake filesystem provided by pyfakefs.

If I run another test that uses requests, I get this error message:

def test_my_unit_test_using_requests(fs):

    test_using_requests()

OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /Users/***/.local/share/virtualenvs/***/lib/python***/site-packages/certifi/cacert.pem

It seems that pyfakefs also generates a fake filesystem for some of Python (or pipenv for that matter) core filesystems breaking requests.

additional_skip_names seems to be the solution for this problem but I can't get it to work. Should it be applied to my test with a parametrized fixture? I have tried this without success:

import pytest
import requests
@pytest.mark.parametrize("fs", [[{"additional_skip_names": requests}]], indirect=True)
def test_my_unit_test(fs):

    test_using_requests()
Nicolas Berthier
  • 459
  • 1
  • 8
  • 17
  • Until I find a better solution I ended up doing something horrible - adding the Python executables path (`path.dirname(path.dirname(sys.executable))`) as a [real directoty](https://pytest-pyfakefs.readthedocs.io/en/latest/usage.html#access-to-files-in-the-real-file-system) in my fixture (with `read_only=True` though) – Nicolas Berthier Jun 06 '23 at 16:06
  • 1
    I missed this one. It is true that `pyfakefs` patches the filesystem for all loaded modules, so if you want to exclude some modules from that `skip_names` could indeed help. If you have a reproducible example I may have a closer look at your concrete problem (you may create an issue in `pyfakefs`, that would be easier to handle). – MrBean Bremen Aug 19 '23 at 18:02

0 Answers0