Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute tests if git is not installed #101

Open
lansman opened this issue Jun 26, 2015 · 4 comments
Open

Cannot execute tests if git is not installed #101

lansman opened this issue Jun 26, 2015 · 4 comments

Comments

@lansman
Copy link

lansman commented Jun 26, 2015

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
Copy link
Owner

peritus commented Jun 26, 2015

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
Copy link
Owner

peritus commented Jun 26, 2015

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
Copy link

tantale commented Jun 26, 2015

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.

@peritus
Copy link
Owner

peritus commented Nov 9, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants