bumpversion icon indicating copy to clipboard operation
bumpversion copied to clipboard

Cannot execute tests if git is not installed

Open lansman opened this issue 10 years ago • 4 comments

Windows 7, bumpversion 0.5.3 There is no git command on my machine so test.py falls immediately.

__________________________ ERROR collecting tests.py __________________________
tests.py:31: in <module>
    call(["git", "help"]) != 0,
C:\Python27\ArcGIS10.2\lib\subprocess.py:522: in call
    return Popen(*popenargs, **kwargs).wait()
C:\Python27\ArcGIS10.2\lib\subprocess.py:710: in __init__
    errread, errwrite)
C:\Python27\ArcGIS10.2\lib\subprocess.py:958: in _execute_child
    startupinfo)
E   WindowsError: [Error 2]
=========================== 1 error in 1.35 seconds ===========================

Let's consider change tests.py so developer can skip tests required git and execute another ones.

lansman avatar Jun 26 '15 11:06 lansman

Good call,

xfail_if_no_git = pytest.mark.xfail(
  call(["git", "help"]) != 0,
  reason="git is not installed"
)

[https://github.com/peritus/bumpversion/blob/5d1749ad7fd76cb8a166de8cf7774b30e9cbe217/tests/test_cli.py#L30-L33]

should probably be something along the lines of

def _is_git_installed():
    try:
        return call(["git", "help"]) == 0
    except WindowsError:
        return False

xfail_if_no_git = pytest.mark.xfail(
  not _is_git_installed(),
  reason="git is not installed"
)

(same for mercurial perhaps)

Sorry, never tried executing the tests on windows without git installed.

Want to submit a pull request ?

peritus avatar Jun 26 '15 12:06 peritus

Also, there's a few tests still failing on windows (see #73 #72 #64 for discussions). If you have any knowledge that could help us get windows 100% supported I would be forever grateful :)

peritus avatar Jun 26 '15 12:06 peritus

In fact, this is not a Windows problem. For example, when mercurial is not installed, you have the same problem.

I think the right way to check if a VCS tool is installed is as follow:

def is_installed(cmd):
    """
    Check that a command is installed and its help message can be displayed.

    This function works well for "git", "hg" and "svn" if their ``bin`` path
    are in the PATH environment variable.

    :param cmd: Name of the command.
    :return: True if the command is installed, otherwise False.
    """
    try:
        args = [cmd, "help"]
        if hasattr(subprocess, "DEVNULL"):
            # Py3 has DEVNULL
            return subprocess.check_call(args,
                                         stdout=subprocess.DEVNULL,
                                         env=SUBPROCESS_ENV) or True
        else:
            from os import devnull

            with open(devnull, b"wb") as DEVNULL:
                return subprocess.check_call(args,
                                             stdout=DEVNULL,
                                             env=SUBPROCESS_ENV) or True
    except EnvironmentError:
        # command not found
        return False

Then, you can rewrite the xfail_if_no_* functions:

xfail_if_no_git = pytest.mark.xfail(
    not is_installed("git"),
    reason="git is not installed"
)

xfail_if_no_hg = pytest.mark.xfail(
    not is_installed("hg"),
    reason="hg is not installed"
)

Regards, – Laurent.

tantale avatar Jun 26 '15 21:06 tantale

This seems like an awful lot of code just to figure out whether git/hg is installed or not, I'm quite hesitant to merge it just because of that.

Nevertheless, the test suite should work whether or not git is installed.

peritus avatar Nov 09 '15 16:11 peritus