According to the documentation for unittest.TestLoader.discover:
discover(start_dir, pattern=’test*.py’, top_level_dir=None)
... All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately...
I've done some experiments myself, and it seems that when top_level_dir
is different to start_dir
and is not set, nothing went wrong: all tests are discovered and imported properly.
I wonder what's the purpose of passing a top_level_dir
argument to discover
. Why would it need to know that's top directory is? I suppose all its job is to (i) find testing packages/modules in start_dir
, and (ii) import them, isn't it?
Or, can someone provide an example where the absence of top_level_dir
causes test discovery to at least partially fail?