简体   繁体   中英

In "unittest discover", what does the "-t" option do?

The Python documentation states that the -t option controls the:

Top level directory of project (defaults to start directory)

Usually people use the -s option ( python -m unittest discover tests/ is equivalent to python -m unittest discover -s tests ), and I have never seen anyone use -t before. The brief description in the documentation is not enlightening to me.

What does the "top level directory" mean in this particular context? What exactly does the -t option do?

My understanding is that although the top-level directory defaults to whatever the starting directory is, the starting directory must be contained by the test directory.

From the first paragraph on test discovery :

Unittest supports simple test discovery. In order to be compatible with test discovery, all of the test files must be modules or packages (including namespace packages) importable from the top-level directory of the project (this means that their filenames must be valid identifiers).

Suppose you have a directory structure like

./
   tests1/
   tests2/

If ./ is the top-level directory and tests1 is the starting directory, no tests will discovered under tests2 , even though tests2 is importable from the top-level directory.

The purpose of -s would be to discover only a subset of tests for a particular project. The purpose of -t might be to choose a particular "subproject" to run tests for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM