| commit | 50f53a18e1d86b0557293e9482376ec62d00ac62 | [log] [tgz] |
|---|---|---|
| author | Erik Massop <emassop@google.com> | Sat Aug 03 18:29:57 2019 +0100 |
| committer | mrbean-bremen <mrbean-bremen@users.noreply.github.com> | Sat Aug 03 20:35:32 2019 +0200 |
| tree | ca96d51bc30bb67c681e192892ff6fa187c87522 | |
| parent | 3f33b0942ba1459cfb76e983c2b44724f866c93f [diff] |
Avoid relative path corner-cases in scandir tests. On Windows the initial cwd of the fake filesystem seems to be \ [3] and the base_path of the fixture is C:\basepath [4]. I don't know what the relative paths from \ to paths below C:\basepath are, since Windows seems to have per-drive roots instead of a single one [2]. If it's C:\basepath\..., it's actually an absolute path on Windows, negating the purpose of the tests that use relative paths. On non-Windows systems, the initial cwd of the fake filesystem seems to be /, so that the relative paths are relative to the root. That might hide problems where the current working directory is not taken into account and instead paths are interpreted relative to the root, lowering the value of the tests that use relative paths. By changing the working directory to self.base_path in setUp, this patch let's us avoid problems like the above. [2] https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats [3] https://github.com/jmcgeheeiv/pyfakefs/blob/7e6f845a795ee6be7783f15033b623f08b2707ed/pyfakefs/fake_filesystem.py#L894 [4] https://github.com/jmcgeheeiv/pyfakefs/blob/7e6f845a795ee6be7783f15033b623f08b2707ed/pyfakefs/tests/test_utils.py#L344-L346
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.
This file provides general usage instructions for pyfakefs. There is more:
In your own documentation, please link to pyfakefs using the canonical URL http://pyfakefs.org. This URL always points to the most relevant top page for pyfakefs.
pyfakefs has support for unittest and pytest, but can also be used directly using fake_filesystem_unittest.Patcher. Refer to the usage documentation for more information on test scenarios, test customization and using convenience functions.
pyfakefs works with CPython 2.7, 3.4 and above, on Linux, Windows and OSX (MacOS), and with PyPy2 and PyPy3.
pyfakefs works with PyTest version 2.8.6 or above.
pyfakefs will not work with Python libraries that use C libraries to access the file system. This is because pyfakefs cannot patch the underlying C libraries' file access functions--the C libraries will always access the real file system. For example, pyfakefs will not work with lxml. In this case lxml must be replaced with a pure Python alternative such as xml.etree.ElementTree.
pyfakefs is currently automatically tested:
pyfakefs unit tests can be run using unittest or pytest:
$ cd pyfakefs/ $ export PYTHONPATH=$PWD $ python -m pyfakefs.tests.all_tests $ python -m pyfakefs.tests.all_tests_without_extra_packages $ python -m pytest pyfakefs/pytest_tests/pytest_plugin_test.py
These scripts are called by tox and Travis-CI. tox can be used to run tests locally against supported python versions:
$ tox
The Dockerfile at the top of the repository will run the tests on the latest Ubuntu version. Build the container:
cd pyfakefs/ docker build -t pyfakefs .
Run the unit tests in the container:
docker run -t pyfakefs
We always welcome contributions to the library. Check out the Contributing Guide for more information.
pyfakefs.py was initially developed at Google by Mike Bland as a modest fake implementation of core Python modules. It was introduced to all of Google in September 2006. Since then, it has been enhanced to extend its functionality and usefulness. At last count, pyfakefs is used in over 2,000 Python tests at Google.
Google released pyfakefs to the public in 2011 as Google Code project pyfakefs:
After the shutdown of Google Code was announced, John McGehee merged all three Google Code projects together here on GitHub where an enthusiastic community actively supports, maintains and extends pyfakefs.