Visitar URL original
list duplicate test names with patchcheck · Issue #60283 · python/cpython · GitHub
Skip to content

list duplicate test names with patchcheck #60283

Description

@xdegaye
mannequin
BPO 16079
Nosy @rhettinger, @gpshead, @vstinner, @rbtcollins, @ned-deily, @ezio-melotti, @merwok, @cjerdonek, @xdegaye, @ambv, @miss-islington
PRs
  • bpo-16079: fix duplicate test method name in test_gzip. #12827
  • [3.7] bpo-16079: fix duplicate test method name in test_gzip. (GH-12827) #12828
  • bpo-16079: Add the duplicate_meth_defs.py tool as a pre-commit check on Travis #12886
  • [2.7] bpo-16079: Add the duplicate_meth_defs.py tool (GH-12886) #12940
  • [3.7] bpo-16079: Add the duplicate_meth_defs.py tool as a pre-commit check on Travis (GH-12886) #12950
  • Files
  • duplicate_test_names.patch
  • duplicate_code_names.py
  • std_lib_duplicates.txt
  • duplicate_code_names_2.py
  • ignored_duplicates
  • duplicate_code_names_3.py
  • 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

    Activity

    1. xdegaye commented on Sep 28, 2012

      xdegayemannequin
      MannequinAuthor

      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:

      ==================

      $ make patchcheck
      ./python ./Tools/scripts/patchcheck.py
      Getting the list of files that have been added/changed ... 1 file
      Fixing whitespace ... 0 files
      Fixing C file whitespace ... 0 files
      Fixing docs whitespace ... 0 files
      Duplicate test names ... 1 test:
        TestErrorHandling.test_get_only in file Lib/test/test_heapq.py
      Docs modified ... NO
      Misc/ACKS updated ... NO
      Misc/NEWS updated ... NO
      configure regenerated ... not needed
      pyconfig.h.in regenerated ... not needed

      Did you run the test suite?

      ==================

    2. added
      type-featureA feature request or enhancement
      stdlibStandard Library Python modules in the Lib/ directory
      on Sep 28, 2012
    3. merwok commented on Sep 28, 2012

      @merwok
      Member

      Nice feature to do without adding a dependency on a lint tool!

    4. cjerdonek commented on Sep 28, 2012

      @cjerdonek
      Member

      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_'.

    5. ezio-melotti commented on Sep 28, 2012

      @ezio-melotti
      Member

      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

      +1
      It can be added to Tools/scripts and imported by patchcheck.

      I'm pretty sure we have some tests that don't start with 'test_'.

      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.

    6. cjerdonek commented on Sep 28, 2012

      @cjerdonek
      Member

      Here are a couple examples of test method names that don't begin with "test_":

          def testLoadTk(self):
          def testLoadTkFailure(self):

      http://hg.python.org/cpython/file/f1094697d7dc/Lib/tkinter/test/test_tkinter/test_loadtk.py#l9

    7. merwok commented on Sep 28, 2012

      @merwok
      Member

      sqlite3 tests use CheckThing style (urgh).

    8. ezio-melotti commented on Sep 28, 2012

      @ezio-melotti
      Member

      Here are a couple examples of test method names that don't begin with "test_":

      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.

    9. cjerdonek commented on Sep 28, 2012

      @cjerdonek
      Member

      I thought you were talking about test files.

      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?

    10. xdegaye commented on Sep 28, 2012

      xdegayemannequin
      MannequinAuthor

      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:

          if not name[-1].startswith('<'):
              yield '.'.join(name)

      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:

          if len(name) > 2 and not name[-1].startswith('<'):
              yield '.'.join(name)

      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.

    11. xdegaye commented on Sep 28, 2012

      xdegayemannequin
      MannequinAuthor

      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.

    12. ezio-melotti commented on Sep 28, 2012

      @ezio-melotti
      Member

      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.

      I'm not sure if there is ever a use case for duplicate
      method names. Is there?

      Nothing that can't be done in a more elegant way afaict.

      It might make sense for variables though, where you have e.g.:

      foo = do_something(x)
      foo = do_something_more(foo)
    13. xdegaye commented on Sep 29, 2012

      xdegayemannequin
      MannequinAuthor

      I'm not sure if there is ever a use case for duplicate method
      names. Is there?

      property getter, setter, and deleter methods do have the same name.

    14. xdegaye commented on Sep 29, 2012

      xdegayemannequin
      MannequinAuthor

      Here are a couple examples of test method names that don't begin
      with "test_":

      def testLoadTk(self):
      def testLoadTkFailure(self):
      

      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_".

    15. 27 remaining items

    16. transferred this issue fromon Apr 10, 2022
    17. erlend-aasland commented on Jun 27, 2023

      @erlend-aasland
      Contributor
    18. merwok commented on Jun 27, 2023

      @merwok
      Member

      Isn’t that repo for tooling and meta issues?

      IMO this should stay in the CPython tracker for visibility.

    19. erlend-aasland commented on Jun 28, 2023

      @erlend-aasland
      Contributor

      Isn’t that repo for tooling and meta issues?

      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.

    20. merwok commented on Jun 28, 2023

      @merwok
      Member

      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.

    21. erlend-aasland commented on Jun 28, 2023

      @erlend-aasland
      Contributor

      Ok, I reopen the ticket.

    22. added a commit that references this issue on Sep 12, 2023
    23. added a commit that references this issue on Sep 13, 2023
    24. added a commit that references this issue on Sep 13, 2023
    25. added a commit that references this issue on Sep 13, 2023
    26. added a commit that references this issue on Sep 14, 2023
    27. added a commit that references this issue on Sep 15, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)end of lifeeasystdlibStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions