<commit_before># pyfakefs
pyfakefs implements a fake file system that mocks the Python file system modules.
Using pyfakefs, your tests operate on a fake file system in memory without
touching the real disk.  The software under test requires no modification to
work with pyfakefs.

pyfakefs works with Linux, Windows and MacOS.

## Documentation

This file provides general usage instructions for pyfakefs.  There is more:

* The [pyfakfs API Reference](http://jmcgeheeiv.github.io/pyfakefs/)
  contains documentation for each pyfakefs class, method and function
* The [pyfakefs Wiki](../../wiki/Home) provides more detailed information on
  specific topics
* The [Release Notes](CHANGES.md) shows a list of changes in the latest versions

### Link to pyfakefs.org

In your own documentation, please link to pyfakefs using <http://pyfakefs.org>.
This URL always points to the most relevant top page for pyfakefs.

## Usage
There are several approaches to implementing tests using pyfakefs.

### Automatically find and patch
The first approach is to allow pyfakefs to automatically find all real file functions and modules, and stub these out with the fake file system functions and modules.  This is explained in the pyfakefs wiki page
[Automatically find and patch file functions and modules](../../wiki/Automatically-find-and-patch-file-functions-and-modules)
and demonstrated in files `example.py` and `example_test.py`.

### Patch using the PyTest plugin

If you use [PyTest](doc.pytest.org), you will be interested in the PyTest plugin in pyfakefs.
This automatically patches all file system functions and modules in a manner similar to the
[automatic find and patch approach](../../wiki/Automatically-find-and-patch-file-functions-and-modules)
described above.

The PyTest plugin provides the `fs` fixture for use in your test. For example:

```python
def my_fakefs_test(fs):
    # "fs" is the reference to the fake file system<commit_msg>Add protocol to pytest docs link in readme<commit_after># pyfakefs
pyfakefs implements a fake file system that mocks the Python file system modules.
Using pyfakefs, your tests operate on a fake file system in memory without
touching the real disk.  The software under test requires no modification to
work with pyfakefs.

pyfakefs works with Linux, Windows and MacOS.

## Documentation

This file provides general usage instructions for pyfakefs.  There is more:

* The [pyfakfs API Reference](http://jmcgeheeiv.github.io/pyfakefs/)
  contains documentation for each pyfakefs class, method and function
* The [pyfakefs Wiki](../../wiki/Home) provides more detailed information on
  specific topics
* The [Release Notes](CHANGES.md) shows a list of changes in the latest versions

### Link to pyfakefs.org

In your own documentation, please link to pyfakefs using <http://pyfakefs.org>.
This URL always points to the most relevant top page for pyfakefs.

## Usage
There are several approaches to implementing tests using pyfakefs.

### Automatically find and patch
The first approach is to allow pyfakefs to automatically find all real file functions and modules, and stub these out with the fake file system functions and modules.  This is explained in the pyfakefs wiki page
[Automatically find and patch file functions and modules](../../wiki/Automatically-find-and-patch-file-functions-and-modules)
and demonstrated in files `example.py` and `example_test.py`.

### Patch using the PyTest plugin

If you use [PyTest](https://doc.pytest.org), you will be interested in the PyTest plugin in pyfakefs.
This automatically patches all file system functions and modules in a manner similar to the
[automatic find and patch approach](../../wiki/Automatically-find-and-patch-file-functions-and-modules)
described above.

The PyTest plugin provides the `fs` fixture for use in your test. For example:

```python
def my_fakefs_test(fs):
    # "fs" is the reference to the fake file system
{'fraction_non_alphanumeric': 0.06904458598726115, 'fraction_numerical': 0.0, 'mean_word_length': 4.5609065155807365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6449298', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1014, 'n_words': 514}