Uploaded image for project: 'Request For Comments'
  1. Request For Comments
  2. RFC-229

Python tests should be named test_*.py for pytest support

    Details

    • Type: RFC
    • Status: Implemented
    • Resolution: Done
    • Component/s: DM
    • Labels:
      None

      Description

      Now that we’re beginning to use pytest to run unit tests, it makes sense to use pytest’s default test discovery so that simply running py.test (without arguments) will have pytest discover and run all tests in the tests/ directory. Currently we must type py.test tests/*.py.

      We can achieve this simplicity through a coding standard that specifies all Python unit test modules must be named with the test_ pattern:

      tests/test_example.py
      

      (Our current standard is tests/testExample.py. The Python Style Guide implies this style, and the Python Unit Testing guide assumes this naming style.)

      I think this is a straightforward coding style change that will make life easier in the long run.

      Alternative

      An alternative to changing the names of test modules, while still making py.test work without arguments is to add a configuration file to each repo that tells pytest how to find our test modules.

      I don’t recommend this. I think it’s better just to use a correct and consistent naming schema.

        Attachments

          Issue Links

            Activity

            Hide
            jsick Jonathan Sick added a comment -

            I'm marking this as adopted as there are no concerns about the long-term value of this decision.

            There are two implementation options for this sort of change:

            1. Encourage developers to upgrade their packages as they go, or
            2. Combine this implementation with other codebase changes (RFC-107 and numpydoc).

            I think option 1 will work here since the change is so lightweight (a single git mv commit per repo). A good way to coordinate this will be with a wiki signup page, like we did for Python 3 and pytest.

            Finally, I confirm that implementation is blocked on pybind11 work (see linked ticket). The implementor should also confirm with Pim Schellart [X] that the codebase is ready before going ahead.

            Show
            jsick Jonathan Sick added a comment - I'm marking this as adopted as there are no concerns about the long-term value of this decision. There are two implementation options for this sort of change: Encourage developers to upgrade their packages as they go, or Combine this implementation with other codebase changes ( RFC-107 and numpydoc). I think option 1 will work here since the change is so lightweight (a single git mv commit per repo). A good way to coordinate this will be with a wiki signup page, like we did for Python 3 and pytest. Finally, I confirm that implementation is blocked on pybind11 work (see linked ticket). The implementor should also confirm with Pim Schellart [X] that the codebase is ready before going ahead.
            Hide
            tjenness Tim Jenness added a comment -

            Who is going to coordinate the work of renaming if we are going to adopt the python3 approach? Have you talked to the relevant T/CAMs about ensuring that their developers are aware of this change?

            Show
            tjenness Tim Jenness added a comment - Who is going to coordinate the work of renaming if we are going to adopt the python3 approach? Have you talked to the relevant T/CAMs about ensuring that their developers are aware of this change?
            Hide
            jsick Jonathan Sick added a comment -

            This Confluence page is tracking the migration: https://confluence.lsstcorp.org/pages/viewpage.action?pageId=58950873

            Show
            jsick Jonathan Sick added a comment - This Confluence page is tracking the migration: https://confluence.lsstcorp.org/pages/viewpage.action?pageId=58950873
            Hide
            tjenness Tim Jenness added a comment -

            Jonathan Sick the work triggered by this RFC has been completed. Does this mean the RFC can be marked implemented? Are you waiting for the work on the confluence page to be completed (which I don't think is necessary, since this is a policy RFC).

            Show
            tjenness Tim Jenness added a comment - Jonathan Sick the work triggered by this RFC has been completed. Does this mean the RFC can be marked implemented? Are you waiting for the work on the confluence page to be completed (which I don't think is necessary, since this is a policy RFC).
            Hide
            jsick Jonathan Sick added a comment -

            That's true, I'll update the status to implemented.

            Show
            jsick Jonathan Sick added a comment - That's true, I'll update the status to implemented.

              People

              • Assignee:
                jsick Jonathan Sick
                Reporter:
                jsick Jonathan Sick
                Watchers:
                John Parejko, Jonathan Sick, Pim Schellart [X] (Inactive), Tim Jenness
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Planned End: