Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Fix bugs affecting exception wrapping in rmtree callback#1700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
2814263
fba59aa
5039df3
683a3ee
2fe7f3c
d42cd72
2a32e25
b8e009e
ccbb273
0b88012
7dd5904
196cfbe
100ab98
7604da1
eb51277
333896b
c11b366
f0e15e8
a9b05ec
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,24 +5,24 @@ | ||
# the BSD License: https://opensource.org/license/bsd-3-clause/ | ||
from abc import abstractmethod | ||
import contextlib | ||
from functools import wraps | ||
import getpass | ||
import logging | ||
import os | ||
import os.path as osp | ||
import pathlib | ||
import platform | ||
import re | ||
import shutil | ||
import stat | ||
import subprocess | ||
import sys | ||
import time | ||
from urllib.parse import urlsplit, urlunsplit | ||
import warnings | ||
from.compat importis_win | ||
# typing --------------------------------------------------------- | ||
@@ -42,22 +42,17 @@ | ||
Tuple, | ||
TypeVar, | ||
Union, | ||
TYPE_CHECKING, | ||
cast, | ||
overload, | ||
) | ||
if TYPE_CHECKING: | ||
from git.remote import Remote | ||
from git.repo.base import Repo | ||
from git.config import GitConfigParser, SectionConstraint | ||
from git import Git | ||
from .types import ( | ||
Literal, | ||
SupportsIndex, | ||
@@ -75,7 +70,6 @@ | ||
# --------------------------------------------------------------------- | ||
from gitdb.util import ( # NOQA @IgnorePep8 | ||
make_sha, | ||
LockedFD, # @UnusedImport | ||
@@ -88,7 +82,6 @@ | ||
hex_to_bin, # @UnusedImport | ||
) | ||
# NOTE: Some of the unused imports might be used/imported by others. | ||
# Handle once test-cases are back up and running. | ||
# Most of these are unused here, but are for use by git-python modules so these | ||
@@ -116,14 +109,33 @@ | ||
log = logging.getLogger(__name__) | ||
def _read_env_flag(name: str, default: bool) -> bool: | ||
try: | ||
value = os.environ[name] | ||
except KeyError: | ||
return default | ||
log.warning( | ||
"The %s environment variable is deprecated. Its effect has never been documented and changes without warning.", | ||
EliahKagan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
name, | ||
) | ||
adjusted_value = value.strip().lower() | ||
if adjusted_value in {"", "0", "false", "no"}: | ||
return False | ||
if adjusted_value in {"1", "true", "yes"}: | ||
return True | ||
log.warning("%s has unrecognized value %r, treating as %r.", name, value, default) | ||
return default | ||
#: We need an easy way to see if Appveyor TCs start failing, | ||
#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy, | ||
#: till then, we wish to hide them. | ||
HIDE_WINDOWS_KNOWN_ERRORS = is_win and_read_env_flag("HIDE_WINDOWS_KNOWN_ERRORS", True) | ||
HIDE_WINDOWS_FREEZE_ERRORS = is_win and_read_env_flag("HIDE_WINDOWS_FREEZE_ERRORS", True) | ||
# { Utility Methods | ||
@@ -177,25 +189,29 @@ def patch_env(name: str, value: str) -> Generator[None, None, None]: | ||
def rmtree(path: PathLike) -> None: | ||
"""Remove the givendirectory treerecursively. | ||
:note:We use:func:`shutil.rmtree` but adjust its behaviour to see whether files that | ||
couldn't be deleted are read-only. Windows will not remove them in that case.""" | ||
def handler(function: Callable, path: PathLike, _excinfo: Any) -> None: | ||
"""Callback for :func:`shutil.rmtree`. Works either as ``onexc`` or ``onerror``.""" | ||
# Is the error an access error? | ||
os.chmod(path, stat.S_IWUSR) | ||
try: | ||
function(path) | ||
exceptPermissionError as ex: | ||
if HIDE_WINDOWS_KNOWN_ERRORS: | ||
from unittest import SkipTest | ||
raise SkipTest(f"FIXME: fails with: PermissionError\n {ex}") from ex | ||
raise | ||
if sys.version_info >= (3, 12): | ||
shutil.rmtree(path, onexc=handler) | ||
else: | ||
shutil.rmtree(path, onerror=handler) | ||
def rmfile(path: PathLike) -> None: | ||
@@ -995,7 +1011,7 @@ def __init__( | ||
self, | ||
file_path: PathLike, | ||
check_interval_s: float = 0.3, | ||
max_block_time_s: int =sys.maxsize, | ||
) -> None: | ||
"""Configure the instance | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,4 +7,5 @@ pre-commit | ||
pytest | ||
pytest-cov | ||
pytest-instafail | ||
pytest-subtests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I've used the I think this is useful to have going forward, since we have many test cases that are large with many separate assertions of separate facts about the system under test, and as they are updated, some of them could be improved by having their separate claims divided into subtests so they can be individually described and so failures don't unnecessarily block later subtests. However, if you'd rather this plugin be used, it can be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I all sounds reasonable and in particular, since you are the one doing the work it seems fair that you can use the tooling you see as best fit. I also have no experience here and no preferences, and believe that anything that improves the tests in any way is very welcome. Thank you! MemberAuthor
| ||
pytest-sugar |
Uh oh!
There was an error while loading.Please reload this page.