PHP 8.2.30
Preview: pytest_doctest_test.py Size: 1.36 KB
/proc/thread-self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/pyfakefs/pytest_tests/pytest_doctest_test.py

"""
This is a test case for pyfakefs issue #45.
This problem is resolved by using PyTest version 2.8.6 or above.

To run these doctests, install pytest and run:

    $ pytest --doctest-modules pytest_doctest_test.py

Add `-s` option to enable print statements.
"""


def make_file_factory(func_name, fake, result):
    """Return a simple function with parametrized doctest."""

    def make_file(name, content=""):
        with open(name, "w") as f:
            f.write(content)

    make_file.__doc__ = """
        >>> import os
        >>> {command}
        >>> name, content = 'foo', 'bar'
        >>> {func_name}(name, content)
        >>> open(name).read() == content
        {result}
        >>> os.remove(name)  # Cleanup
        """.format(
        command="getfixture('fs')" if fake else "pass",
        func_name=func_name,
        result=result,
    )

    return make_file


passes = make_file_factory("passes", fake=False, result=True)
passes_too = make_file_factory("passes_too", fake=True, result=True)

passes_too.__doc__ = passes_too.__doc__.replace(">>> os.remove(name)", ">>> pass")

fails = make_file_factory("fails", fake=False, result=False)

# Pytest versions below 2.8.6 raise an internal error when running
# these doctests:
crashes = make_file_factory("crashes", fake=True, result=False)
crashes_too = make_file_factory(") SyntaxError", fake=True, result=False)

Directory Contents

Dirs: 4 × Files: 19

Name Size Perms Modified Actions
data DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
hook_test DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:05
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
1.30 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
652 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
855 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
341 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
75 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
132 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
659 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.36 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.85 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.48 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.02 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
128 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
828 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
348 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
949 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
771 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
390 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).