packaging.python.org icon indicating copy to clipboard operation
packaging.python.org copied to clipboard

`test` vs. `tests`

Open DimitriPapadopoulos opened this issue 3 years ago • 4 comments

Should tests live in directory test or tests? The guide seems inconsistent to me, but I'm new to contemporary Python packaging, so I may have missed something.

It is test in guides/using-manifest-in.rst:

How files are included in an sdist

The following files are included in a source distribution by default:

  • ...
  • all files matching the pattern test/test*.py

and tests in tutorials/packaging-projects.rst:

Creating a test directory

tests/ is a placeholder for test files. Leave it empty for now.

Is tests always the expected name for the directory containing tests? Could/should the guide standardize on that?

DimitriPapadopoulos avatar Nov 16 '22 20:11 DimitriPapadopoulos

I think you're right, using the plural tests/ is more common. The name is not restricted programmatically, but it is nicer to have a unified convention. So far, I've only seen one project using a singular test/ folder, but they are moving toward tests/ where possible, too.

webknjaz avatar Nov 19 '22 15:11 webknjaz

The name has to be matched/restricted at some point:

The following files are included in a source distribution by default:

  • ...
  • all files matching the pattern test/test*.py

I cannot find the relevant code in the pypa repositories, as I don't know which package would do the matching.

The pypa repositories seem to be commonly using test/.

DimitriPapadopoulos avatar Nov 20 '22 10:11 DimitriPapadopoulos

I think I have found the relevant source code in setuptools:

setuptools/_distutils/command/sdist.py Lines 295 to 296 in 59ee498

    def _add_defaults_optional(self):
        optional = ['test/test*.py', 'setup.cfg']

copied over from distutils:

distutils/command/sdist.py Lines 295 to 296 in e0787fa

    def _add_defaults_optional(self):
        optional = ['test/test*.py', 'setup.cfg']

DimitriPapadopoulos avatar Nov 20 '22 12:11 DimitriPapadopoulos

I have created https://github.com/pypa/distutils/issues/187 to investigate directly in distutils.

DimitriPapadopoulos avatar Nov 20 '22 14:11 DimitriPapadopoulos