Skip to content

Commit

Permalink
Merge pull request #6 from nicoddemus/drop-dup-files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored May 23, 2020
2 parents f8a18c0 + 4e29e4a commit 94c8210
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 74 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [2.7, 3.8]
tox-env: ["py27", "py36", "py37", "py38", "linting"]
include:
- tox-env: "py27"
python-version: "2.7"
- tox-env: "py36"
python-version: "3.6"
- tox-env: "py37"
python-version: "3.7"
- tox-env: "py38"
python-version: "3.8"
- tox-env: "linting"
python-version: "3.8"

steps:
- uses: actions/checkout@v1
Expand All @@ -20,17 +31,17 @@ jobs:
- name: Dependencies
run: |
python -m pip install --upgrade pip
pip install tox
pip install tox
- name: Test
run: |
tox -e py
tox -e ${{ matrix.tox-env }}
deploy:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v1
- name: Set up Python
Expand All @@ -44,7 +55,7 @@ jobs:
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Publish package to PyPI
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
Expand Down
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: local
hooks:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
files: ^(CHANGELOG.rst|README.rst)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.3.0
=====

- Files passed on the command-line are now deduplicated as well (`#5`_).

.. _#5: https://github.com/nicoddemus/pytest-drop-dup-tests/issues/5

0.2.0
=====

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
7 changes: 0 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ This plugin was born from the discussion taken in `#1187`_.
This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.


Requirements
------------

* Python 2.7 or 3.5+
* pytest >= 2.7


Installation
------------

Expand Down
25 changes: 19 additions & 6 deletions pytest_drop_dup_tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@


_seen = set()
_seen_paths = set()


def pytest_ignore_collect(path, config):
if path.basename == '__init__.py':
if path.basename == "__init__.py":
return None
if path in _seen:
if path in _seen_paths:
return True
else:
_seen.add(path)
_seen_paths.add(path)
return None


def pytest_collection_modifyitems(config, items):
seen_node_ids = set()
new_items = []
deselected_items = []
for item in items:
if item.nodeid not in seen_node_ids:
new_items.append(item)
seen_node_ids.add(item.nodeid)
else:
deselected_items.append(item)

items[:] = new_items
config.hook.pytest_deselected(items=deselected_items)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
62 changes: 28 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,38 @@

def read(fname):
file_path = os.path.join(os.path.dirname(__file__), fname)
return codecs.open(file_path, encoding='utf-8').read()
return codecs.open(file_path, encoding="utf-8").read()


setup(
name='pytest-drop-dup-tests',
version='0.1.0',
author='Bruno Oliveira',
author_email='nicoddemus@gmail.com',
maintainer='Bruno Oliveira',
maintainer_email='nicoddemus@gmail.com',
license='MIT',
url='https://github.com/nicoddemus/pytest-drop-dup-tests',
description='A Pytest plugin to drop duplicated tests during collection',
long_description=read('README.rst'),
py_modules=['pytest_drop_dup_tests'],
setup_requires='setuptools_scm',
name="pytest-drop-dup-tests",
author="Bruno Oliveira",
author_email="nicoddemus@gmail.com",
maintainer="Bruno Oliveira",
maintainer_email="nicoddemus@gmail.com",
license="MIT",
url="https://github.com/nicoddemus/pytest-drop-dup-tests",
description="A Pytest plugin to drop duplicated tests during collection",
long_description=read("README.rst"),
py_modules=["pytest_drop_dup_tests"],
setup_requires="setuptools_scm",
use_scm_version=True,
install_requires=['pytest>=2.7'],
install_requires=["pytest>=2.7"],
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Pytest',
'Intended Audience :: Developers',
'Topic :: Software Development :: Testing',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Operating System :: OS Independent',
'License :: OSI Approved :: MIT License',
"Development Status :: 4 - Beta",
"Framework :: Pytest",
"Intended Audience :: Developers",
"Topic :: Software Development :: Testing",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
],
entry_points={
'pytest11': [
'drop-dup-tests = pytest_drop_dup_tests',
],
},
entry_points={"pytest11": ["drop-dup-tests = pytest_drop_dup_tests",],},
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest_plugins = 'pytester'
pytest_plugins = "pytester"
61 changes: 45 additions & 16 deletions tests/test_drop_dup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,55 @@


def test_drop_duplicated_dir(testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
def test_foo():
pass
""")
result = testdir.runpytest('.', '.')
result.stdout.fnmatch_lines([
'* 1 passed in *',
])
"""
)
result = testdir.runpytest(".", ".")
result.stdout.fnmatch_lines(
["* 1 passed in *",]
)
assert result.ret == 0


def test_drop_duplicated_pkg(testdir):
testdir.makepyfile(**{
"pkg/__init__.py": "",
"pkg/test_foo.py": """
def test_foo():
pass
"""})
result = testdir.runpytest('pkg', 'pkg')
result.stdout.fnmatch_lines([
'* 1 passed in *',
])
testdir.makepyfile(
**{
"pkg/__init__.py": "",
"pkg/test_foo.py": """
def test_foo():
pass
""",
}
)
result = testdir.runpytest("pkg", "pkg")
result.stdout.fnmatch_lines(
["* 1 passed in *",]
)
assert result.ret == 0


def test_drop_duplicated_files(testdir):
testdir.makepyfile(
**{
"tests/test_foo.py": """
def test_foo():
pass
""",
"tests/test_bar.py": """
def test_bar():
pass
""",
}
)
result = testdir.runpytest("tests", "tests/test_foo.py", "-v")
result.stdout.fnmatch_lines(
[
"tests/test_bar.py::test_bar *",
"tests/test_foo.py::test_foo *",
"* 2 passed, 1 deselected in *",
]
)
assert result.ret == 0
11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# For more information about tox, see https://tox.readthedocs.org/en/latest/
[tox]
envlist = py27,py33,py34,py35,pypy
envlist = py27,py36,py37,py38,linting

[testenv]
deps = pytest
commands = py.test {posargs:tests}
commands = pytest {posargs:tests}

[testenv:linting]
skip_install = True
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure

0 comments on commit 94c8210

Please sign in to comment.