├── MANIFEST.in ├── setup.cfg ├── tests ├── test_should_run.py └── test_should_not_run.py ├── tox.ini ├── CHANGELOG.md ├── README.txt ├── setup.py ├── .gitignore ├── LICENSE └── pytest_gitignore.py /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /tests/test_should_run.py: -------------------------------------------------------------------------------- 1 | """ 2 | This test file should run, and its test should pass. 3 | """ 4 | 5 | 6 | def test_that_1_is_1(): 7 | assert 1 == 1 8 | -------------------------------------------------------------------------------- /tests/test_should_not_run.py: -------------------------------------------------------------------------------- 1 | """ 2 | This test should be excluded by the command line arg in tox.ini. 3 | """ 4 | 5 | 6 | def test_should_not_run(): 7 | assert "never" == "always" 8 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py34 3 | 4 | [testenv] 5 | whitelist_externals = cp 6 | commands = 7 | cp tests/test_should_not_run.py tests/test_should_be_gitignored.py 8 | py.test --ignore tests/test_should_not_run.py 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Version 1.3 2 | ----------- 3 | 4 | * Use py.test 2.7's "hookwrapper" decorator to allow use of the --ignore 5 | command line argument. 6 | 7 | * Add some very basic tests with tox. 8 | 9 | 10 | Version 1.2 11 | ----------- 12 | 13 | * Include the license, classifiers, etc. 14 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | pytest-gitignore 2 | ================ 3 | 4 | This py.test plugin will tell py.test to ignore any file that git 5 | ignores, when it's collecting tests. For example, if you keep virtualenvs 6 | in your source directory, you can have both git and py.test ignore them 7 | by putting them in your .gitignore. To see whether a file is ignored 8 | by git, run `git check-ignore (filename)`. 9 | 10 | This plugin is registered as 'gitignore'. 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | setup( 5 | name = 'pytest-gitignore', 6 | version = '1.3', 7 | description = 'py.test plugin to ignore the same files as git', 8 | url = 'https://github.com/tgs/pytest-gitignore', 9 | long_description = open('README.txt').read(), 10 | author = 'Thomas Grenfell Smith', 11 | author_email = 'smithtg@ncbi.nlm.nih.gov', 12 | py_modules = ['pytest_gitignore'], 13 | entry_points = { 14 | 'pytest11': [ 15 | 'gitignore = pytest_gitignore', 16 | ], 17 | }, 18 | classifiers = [ 19 | 'License :: Public Domain', 20 | 'Programming Language :: Python :: 2', 21 | 'Programming Language :: Python :: 3', 22 | 'Topic :: Software Development :: Testing', 23 | 'Intended Audience :: Developers', 24 | 'Development Status :: 4 - Beta', 25 | 'Topic :: Software Development :: Version Control', 26 | ], 27 | install_requires = [ 28 | 'pytest>=2.7', 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | 59 | # Test that the thing actually works. 60 | tests/test_should_be_gitignored.py 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Public Domain notice 2 | ==================== 3 | 4 | National Center for Biotechnology Information. 5 | 6 | This software is a "United States Government Work" under the terms of the 7 | United States Copyright Act. It was written as part of the authors' 8 | official duties as United States Government employees and thus cannot 9 | be copyrighted. This software is freely available to the public for 10 | use. The National Library of Medicine and the U.S. Government have not 11 | placed any restriction on its use or reproduction. 12 | 13 | Although all reasonable efforts have been taken to ensure the accuracy 14 | and reliability of the software and data, the NLM and the U.S. 15 | Government do not and cannot warrant the performance or results that 16 | may be obtained by using this software or data. The NLM and the U.S. 17 | Government disclaim all warranties, express or implied, including 18 | warranties of performance, merchantability or fitness for any 19 | particular purpose. 20 | 21 | Please cite NCBI in any work or product based on this material. 22 | 23 | -------------------------------------------------------------------------------- /pytest_gitignore.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | import pytest 4 | 5 | 6 | @pytest.mark.hookwrapper 7 | def pytest_ignore_collect(path, config): 8 | outcome = yield # use pytest's command line args, etc. 9 | if not outcome.get_result(): 10 | # not ignored by the default hook 11 | 12 | if git_ignores_path(path): 13 | # don't force a False result: 14 | # another plugin might want to ignore this file. 15 | outcome.force_result(True) 16 | 17 | 18 | def git_ignores_path(path): 19 | if path.basename == '.git': # Ignore .git directory 20 | return True 21 | child = subprocess.Popen(['git', 'check-ignore', str(path)], 22 | stdout=subprocess.PIPE, 23 | stderr=subprocess.PIPE) 24 | output = child.communicate()[0] 25 | status = child.wait() 26 | # Possible return values: (via git help check-ignore) 27 | # 0: Yes, the file is ignored 28 | # 1: No, the file isn't ignored 29 | # 128: Fatal error, git can't tell us whether to ignore 30 | # 31 | # The latter happens a lot with python virtualenvs, since they have 32 | # symlinks and git gives up when you try to follow one. But maybe you have 33 | # a test directory that you include with a symlink, who knows? So we treat 34 | # the file as not-ignored. 35 | return status == 0 36 | --------------------------------------------------------------------------------