Skip to content

Commit

Permalink
feature: use --skip-duplicates to ignore duplicate tests and take int…
Browse files Browse the repository at this point in the history
…o account only the first one.
  • Loading branch information
ioggstream committed Jul 23, 2016
1 parent ae07985 commit 83fabcc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Punyashloka Biswal
Quentin Pradet
Ralf Schmitt
Raphael Pierzina
Roberto Polli
Roman Bolshakov
Ronny Pfannschmidt
Ross Lawley
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ time or change existing behaviors in order to make them less surprising/more use
fixtures and reports them;
+ ``--setup-show``: performs normal test execution and additionally shows
setup and teardown of fixtures;
+ ``--skip-duplicates``: ignore duplicate tests, taking into account only
the first one `#1609`_;

Thanks `@d6e`_, `@kvas-it`_, `@sallner`_ and `@omarkohl`_ for the PRs.
Thanks `@d6e`_, `@kvas-it`_, `@sallner`_, `@ioggstream`_ and `@omarkohl`_ for the PRs.

* New cli flag ``--override-ini``/``-o``: overrides values from the ini file.
For example: ``"-o xfail_strict=True"``'.
Expand Down Expand Up @@ -514,6 +516,7 @@ time or change existing behaviors in order to make them less surprising/more use

.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing

.. _#1609: https://github.com/pytest-dev/pytest/issues/1609
.. _#1422: https://github.com/pytest-dev/pytest/issues/1422
.. _#1379: https://github.com/pytest-dev/pytest/issues/1379
.. _#1366: https://github.com/pytest-dev/pytest/issues/1366
Expand All @@ -539,6 +542,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@rabbbit: https://github.com/rabbbit
.. _@hackebrot: https://github.com/hackebrot
.. _@pquentin: https://github.com/pquentin
.. _@ioggstream: https://github.com/ioggstream

2.8.7
=====
Expand Down
1 change: 1 addition & 0 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def __init__(self):
self._conftestpath2mod = {}
self._confcutdir = None
self._noconftest = False
self._skipduplicates = set()

self.add_hookspecs(_pytest.hookspec)
self.register(self)
Expand Down
20 changes: 19 additions & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def pytest_addoption(parser):
group.addoption('--noconftest', action="store_true",
dest="noconftest", default=False,
help="Don't load any conftest.py files.")
group.addoption('--skipduplicates', '--skip-duplicates', action="store_true",
dest="skipduplicates", default=False,
help="Skip duplicate tests.")

group = parser.getgroup("debugconfig",
"test session debugging and configuration")
Expand Down Expand Up @@ -154,7 +157,22 @@ def pytest_ignore_collect(path, config):
excludeopt = config.getoption("ignore")
if excludeopt:
ignore_paths.extend([py.path.local(x) for x in excludeopt])
return path in ignore_paths

if path in ignore_paths:
return True

# Skip duplicate paths.
skipduplicates = config.getoption("skipduplicates")
duplicate_paths = config.pluginmanager._skipduplicates
if skipduplicates:
if path.purebasename in duplicate_paths:
# TODO should we log this?
return True
else:
duplicate_paths.add(path.purebasename)

return False


class FSHookProxy:
def __init__(self, fspath, pm, remove_mods):
Expand Down
27 changes: 27 additions & 0 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,3 +1213,30 @@ def test_syntax_error_with_non_ascii_chars(testdir):
'*SyntaxError*',
'*1 error in*',
])


def test_skip_duplicates(testdir):
"""Test for issue https://github.com/pytest-dev/pytest/issues/1609 (#1609)
Ignore duplicate test filenames.
"""
a = testdir.mkdir("a")
b = testdir.mkdir("b")
a.join("test_a.py").write(_pytest._code.Source("""
import pytest
def test_real():
pass
"""))
b.join("test_a.py").write(_pytest._code.Source("""
import pytest
def test_real():
pass
"""))

result = testdir.runpytest('--skip-duplicates')
result.stdout.fnmatch_lines([
'*collected 1 item*',
])



0 comments on commit 83fabcc

Please sign in to comment.