peritus / bumpversion

Version-bump your software with a single command
https://pypi.python.org/pypi/bumpversion
MIT License
1.5k stars 147 forks source link

Cannot execute tests if git is not installed #101

Open lansman opened 9 years ago

lansman commented 9 years ago

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.

peritus commented 9 years ago

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 commented 9 years ago

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 :)

tantale commented 9 years ago

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_ifno* 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.

peritus commented 8 years ago

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.