Open lansman opened 9 years ago
Good call,
xfail_if_no_git = pytest.mark.xfail(
call(["git", "help"]) != 0,
reason="git is not installed"
)
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 ?
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 :)
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.
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.
Windows 7, bumpversion 0.5.3 There is no git command on my machine so test.py falls immediately.
Let's consider change tests.py so developer can skip tests required git and execute another ones.