Repository navigation
list duplicate test names with patchcheck #60283
Copy link
Copy link
Closed
Labels
3.9 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2012-09-28.10:15:37.662>
labels = ['easy', 'tests', 'type-bug', 'library', '3.9']
title = 'list duplicate test names with patchcheck'
updated_at = <Date 2019-11-27.18:45:45.910>
user = 'https://github.com/xdegaye'bugs.python.org fields:
activity = <Date 2019-11-27.18:45:45.910>
actor = 'brett.cannon'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)', 'Tests']
creation = <Date 2012-09-28.10:15:37.662>
creator = 'xdegaye'
dependencies = []
files = ['27326', '27375', '27376', '31891', '31892', '48265']
hgrepos = []
issue_num = 16079
keywords = ['patch', 'easy']
message_count = 31.0
messages = ['171428', '171499', '171505', '171509', '171511', '171512', '171513', '171519', '171536', '171544', '171548', '171558', '171559', '171576', '171734', '198525', '198586', '229625', '340168', '340219', '340221', '340252', '340286', '340295', '340323', '340584', '340585', '340687', '340785', '340786', '351668']
nosy_count = 11.0
nosy_names = ['rhettinger', 'gregory.p.smith', 'vstinner', 'rbcollins', 'ned.deily', 'ezio.melotti', 'eric.araujo', 'chris.jerdonek', 'xdegaye', 'lukasz.langa', 'miss-islington']
pr_nums = ['12827', '12828', '12886', '12940', '12950']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue16079'
versions = ['Python 3.9']Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.9 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
xdegaye commentedon Sep 28, 2012
See also bpo-16056 for the current list of duplicate test names in
the std lib.
The attached patch improves patchcheck.py to list duplicate test
names when running 'make patchcheck'. This patch to the default
branch can also be applied asis to the 2.7 branch.
An example of patchcheck output with the patch applied:
==================
Did you run the test suite?
==================
merwok commentedon Sep 28, 2012
Nice feature to do without adding a dependency on a lint tool!
cjerdonek commentedon Sep 28, 2012
I would like to see this written in a way that would let one run it globally or on a single file independent of a patch (e.g. an independent script from which patchcheck could import certain functions). Or is that what you explicitly didn't want Éric? :)
This would let one do a report or global check as was done for bpo-16056. It would also make it a bit easier to check manually that the script is checking for duplicates correctly.
Also, some suggestions:
+def testmethod_names(code, name=[]):
It might be clearer to use the name=None form.
+ test_files = [fn for fn in python_files if
+ fn.startswith(os.path.join('Lib', 'test'))]
Are you getting the test files in test/ subdirectories of subpackages? I think checking that the file name starts with "test_" might be sufficient to get all test files.
+ if name[-1].startswith('test_'):
I believe 'test' is the prefix that unittest uses. I'm pretty sure we have some tests that don't start with 'test_'.
ezio-melotti commentedon Sep 28, 2012
+1
It can be added to Tools/scripts and imported by patchcheck.
IIRC those are just test helpers that are not executed directly.
OTOH I don't see why looking for test_*, every py file might contain duplicate names so they should all be checked.
cjerdonek commentedon Sep 28, 2012
Here are a couple examples of test method names that don't begin with "test_":
http://hg.python.org/cpython/file/f1094697d7dc/Lib/tkinter/test/test_tkinter/test_loadtk.py#l9
merwok commentedon Sep 28, 2012
sqlite3 tests use CheckThing style (urgh).
ezio-melotti commentedon Sep 28, 2012
I thought you were talking about test files. I still don't see why looking for test_* methods, every class might contain duplicate method names, so they should all be checked.
cjerdonek commentedon Sep 28, 2012
Oh, I see why you said that then. To find the test files themselves, this logic was used in the patch:
+ fn.startswith(os.path.join('Lib', 'test'))]
Regarding your question for the general case, I'm not sure if there is ever a use case for duplicate method names. Is there?
xdegaye commentedon Sep 28, 2012
Note that using the module code object to find duplicates does not
allow for selecting among the different code types: function, nested
function, method or class.
Duplicates are extensively used within the std lib:
Running find_duplicate_test_names.py, the initial script from issue
16056, on the whole std lib instead of just Lib/test, after updating
the script to list all the duplicates (except <lambda>, <genexp>,
...) with:
prints 347 (on a total of 1368 std lib .py files) duplicate
functions, methods or classes.
To eliminate module level functions (but not nested functions), the
script is run now with the following change:
and lists 188 duplicate nested functions, methods or classes. In
this list there are 131 duplicates in .py files located in the
subdirectory of a "test" directory.
xdegaye commentedon Sep 28, 2012
Using the python class browser (pyclbr.py) in conjunction with the
search for duplicates in the module code object would allow to
restrict the listing of duplicates to functions and methods or even
just to methods (depending on the feature requirements), without
listing the duplicate classes and duplicate nested functions. With
an associated performance cost.
ezio-melotti commentedon Sep 28, 2012
It doesn't necessary have to be limited to methods, anything duplicate might turn out to be a bug. If the script doesn't mix scopes there shouldn't be too many false positives, and if they are it shouldn't be a big deal if they are reported on the changed file by
make patchcheck.Nothing that can't be done in a more elegant way afaict.
It might make sense for variables though, where you have e.g.:
xdegaye commentedon Sep 29, 2012
property getter, setter, and deleter methods do have the same name.
xdegaye commentedon Sep 29, 2012
Also Lib/test/test_smtplib.py test method names start with 'test'
instead of 'test_' although the 'Regression tests package for Python'
documentation states: "The test methods in the test module should
start with test_".
27 remaining items
erlend-aasland commentedon Jun 27, 2023
Superseded by python/core-workflow#505
merwok commentedon Jun 27, 2023
Isn’t that repo for tooling and meta issues?
IMO this should stay in the CPython tracker for visibility.
erlend-aasland commentedon Jun 28, 2023
Yes, and CI issues. Most relevant comments in this thread are about running these checks in CI. So it belongs in the core-workflow repo.
merwok commentedon Jun 28, 2023
Oh, in my opinion the tool / config should be available for devs to run locally first, then also run from CI!
That’s why I see this as a normal CPython ticket.
erlend-aasland commentedon Jun 28, 2023
Ok, I reopen the ticket.
gh-60283: Check for redefined test names in CI (#109161)
pythongh-60283: Check for redefined test names in CI (pythonGH-109161)
pythongh-60283: Check for redefined test names in CI (python#109161)
pythongh-60283: Check for redefined test names in CI (python#109161)
[3.12] gh-60283: Check for redefined test names in CI (GH-109161) (#1…
[3.11] gh-60283: Check for redefined test names in CI (#109161) (#109366