Skip to content

Commit

Permalink
Add a note about setUpClassPyfakefs usage
Browse files Browse the repository at this point in the history
- if used with pytest, pytest >= 6.2 is needed
- also remove obsolete Python 3.6 references
  • Loading branch information
mrbean-bremen committed Sep 20, 2023
1 parent 7b9b62f commit d0f3e6a
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Unittest module classes
-----------------------

.. autoclass:: pyfakefs.fake_filesystem_unittest.TestCaseMixin
:members: fs, setUpPyfakefs, pause, resume
:members: fs, setUpPyfakefs, setUpClassPyfakefs, pause, resume

.. autoclass:: pyfakefs.fake_filesystem_unittest.TestCase

Expand Down
3 changes: 2 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ method ``setUpClassPyfakefs`` instead:
self.assertTrue(os.path.exists(file_path))
.. note:: This feature cannot be used with a Python version before Python 3.8 due to
a missing feature in ``unittest``.
a missing feature in ``unittest``. If you use ``pytest`` for running tests using this feature,
you need to have at least ``pytest`` version 6.2 due to an issue in earlier versions.

.. caution:: If this is used, any changes made in the fake filesystem inside a test
will remain there for all following tests in the test class, if they are not reverted
Expand Down
10 changes: 6 additions & 4 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TestCaseMixin:
modules by fake implementations.
Attributes:
additional_skip_names: names of modules inside of which no module
additional_skip_names: names of modules where no module
replacement shall be performed, in addition to the names in
:py:attr:`fake_filesystem_unittest.Patcher.SKIPNAMES`.
Instead of the module names, the modules themselves may be used.
Expand All @@ -220,7 +220,7 @@ class TestCaseMixin:
fully qualified patched module names. Can be used to add patching
of modules not provided by `pyfakefs`.
If you specify some of these attributes here and you have DocTests,
If you specify some of these attributes here, and you have DocTests,
consider also specifying the same arguments to :py:func:`load_doctests`.
Example usage in derived test classes::
Expand Down Expand Up @@ -322,6 +322,8 @@ def setUpClassPyfakefs(
:py:func:`setUpPyfakefs` in the same class will not work correctly.
.. note:: This method is only available from Python 3.8 onwards.
.. note:: If using `pytest` as testrunner, you need at least pytest 6.2
for this method to work.
"""
if sys.version_info < (3, 8):
raise NotImplementedError(
Expand Down Expand Up @@ -516,7 +518,7 @@ def __init__(
) -> None:
"""
Args:
additional_skip_names: names of modules inside of which no module
additional_skip_names: names of modules where no module
replacement shall be performed, in addition to the names in
:py:attr:`fake_filesystem_unittest.Patcher.SKIPNAMES`.
Instead of the module names, the modules themselves
Expand Down Expand Up @@ -1021,7 +1023,7 @@ def resume(self) -> None:
class Pause:
"""Simple context manager that allows to pause/resume patching the
filesystem. Patching is paused in the context manager, and resumed after
going out of it's scope.
going out of its scope.
"""

def __init__(self, caller: Union[Patcher, TestCaseMixin, FakeFilesystem]):
Expand Down
15 changes: 6 additions & 9 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ def getxattr(
`path`.
Args:
path: File path, file descriptor or path-like object (for
Python >= 3.6).
path: File path, file descriptor or path-like object.
attribute: (str or bytes) The attribute name.
follow_symlinks: (bool) If True (the default), symlinks in the
path are traversed.
Expand All @@ -487,8 +486,8 @@ def listxattr(
"""Return a list of the extended filesystem attributes on `path`.
Args:
path: File path, file descriptor or path-like object (for
Python >= 3.6). If None, the current directory is used.
path: File path, file descriptor or path-like object.
If None, the current directory is used.
follow_symlinks: (bool) If True (the default), symlinks in the
path are traversed.
Expand All @@ -512,11 +511,10 @@ def listxattr(
def removexattr(
self, path: AnyStr, attribute: AnyString, *, follow_symlinks: bool = True
) -> None:
"""Removes the extended filesystem attribute attribute from `path`.
"""Removes the extended filesystem attribute from `path`.
Args:
path: File path, file descriptor or path-like object (for
Python >= 3.6).
path: File path, file descriptor or path-like object
attribute: (str or bytes) The attribute name.
follow_symlinks: (bool) If True (the default), symlinks in the
path are traversed.
Expand Down Expand Up @@ -546,8 +544,7 @@ def setxattr(
`path`.
Args:
path: File path, file descriptor or path-like object (for
Python >= 3.6).
path: File path, file descriptor or path-like object.
attribute: The attribute name (str or bytes).
value: (byte-like) The value to be set.
follow_symlinks: (bool) If True (the default), symlinks in the
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/fake_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def samefile(self, path1: AnyStr, path2: AnyStr) -> bool:
"""Return whether path1 and path2 point to the same file.
Args:
path1: first file path or path object (Python >=3.6)
path2: second file path or path object (Python >=3.6)
path1: first file path or path object
path2: second file path or path object
Raises:
OSError: if one of the paths does not point to an existing
Expand Down
3 changes: 1 addition & 2 deletions pyfakefs/fake_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,9 @@ def resolve(self, strict=None):
Args:
strict: If False (default) no exception is raised if the path
does not exist.
New in Python 3.6.
Raises:
OSError: if the path doesn't exist (strict=True or Python < 3.6)
OSError: if the path doesn't exist (strict=True)
"""
if sys.version_info >= (3, 6):
if strict is None:
Expand Down
1 change: 0 additions & 1 deletion pyfakefs/pytest_tests/pytest_fixture_param_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# limitations under the License.

# Example for a test using a custom pytest fixture with an argument to Patcher
# Needs Python >= 3.6
import os

import pytest
Expand Down
1 change: 0 additions & 1 deletion pyfakefs/pytest_tests/pytest_fixture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# limitations under the License.

# Example for a test using a custom pytest fixture with an argument to Patcher
# Needs Python >= 3.6

import pytest

Expand Down
4 changes: 0 additions & 4 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,6 @@ def test_cwd(self, fs):


class TestDeprecationSuppression(fake_filesystem_unittest.TestCase):
@unittest.skipIf(
sys.version_info[1] == 6,
"Test fails for Python 3.6 for unknown reason",
)
def test_no_deprecation_warning(self):
"""Ensures that deprecation warnings are suppressed during module
lookup, see #542.
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5261,8 +5261,8 @@ def test_stat_ino_dev(self):
self.assertEqual(file_stat.st_dev, self.dir_entries[5].stat().st_dev)

@unittest.skipIf(
sys.version_info < (3, 6) or not use_builtin_scandir,
"Path-like objects have been introduced in Python 3.6",
not use_builtin_scandir,
"Path-like objects not available in scandir package",
)
def test_path_like(self):
self.assertTrue(isinstance(self.dir_entries[0], os.PathLike))
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/tests/fake_pathlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ def use_real_fs(self):


class FakePathlibUsageInOsFunctionsTest(RealPathlibTestCase):
"""Test that many os / os.path functions accept a path-like object
since Python 3.6. The functionality of these functions is tested
"""Test that many `os` / `os.path` functions accept a path-like object.
The functionality of these functions is tested
elsewhere, we just check that they accept a fake path object as an
argument.
"""
Expand Down

0 comments on commit d0f3e6a

Please sign in to comment.