def _removeSafely(path):
    """
    Safely remove a path, recursively.

    If C{path} does not contain a node named C{_trial_marker}, a
    L{_NoTrialMarker} exception is raised and the path is not removed.
    """
    if not path.child(b'_trial_marker').exists():
        raise _NoTrialMarker(
            '%r is not a trial temporary path, refusing to remove it'
            % (path,))
    try:
        path.remove()
    except OSError as e:
        print ("could not remove %r, caught OSError [Errno %s]: %s"
               % (path, e.errno, e.strerror))
        try:
            newPath = FilePath(b'_trial_temp_old' +
                               str(randrange(10000000)).encode("utf-8"))
            path.moveTo(newPath)
        except OSError as e:
            print ("could not rename path, caught OSError [Errno %s]: %s"
                   % (e.errno,e.strerror))
            raise

    Safely remove a path, recursively.

    If C{path} does not contain a node named C{_trial_marker}, a
    L{_NoTrialMarker} exception is raised and the path is not removed.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/trial/util.py