-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpytest_gitignore.py
More file actions
35 lines (29 loc) · 1.21 KB
/
pytest_gitignore.py
File metadata and controls
35 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import subprocess
import pytest
@pytest.mark.hookwrapper
def pytest_ignore_collect(path, config):
outcome = yield # use pytest's command line args, etc.
if not outcome.get_result():
# not ignored by the default hook
if git_ignores_path(path):
# don't force a False result:
# another plugin might want to ignore this file.
outcome.force_result(True)
def git_ignores_path(path):
if path.basename == '.git': # Ignore .git directory
return True
child = subprocess.Popen(['git', 'check-ignore', str(path)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = child.communicate()[0]
status = child.wait()
# Possible return values: (via git help check-ignore)
# 0: Yes, the file is ignored
# 1: No, the file isn't ignored
# 128: Fatal error, git can't tell us whether to ignore
#
# The latter happens a lot with python virtualenvs, since they have
# symlinks and git gives up when you try to follow one. But maybe you have
# a test directory that you include with a symlink, who knows? So we treat
# the file as not-ignored.
return status == 0