[Tutor] Do not understand why test is running.

boB Stepp robertvstepp at gmail.com
Mon Aug 24 04:26:21 CEST 2015

On Sun, Aug 23, 2015 at 11:47 AM, Peter Otten <__peter__ at web.de> wrote:
> boB Stepp wrote:

>> And am I misreading the docs at
>> https://docs.python.org/3/library/unittest.html#test-discovery:
> -------------------------------------------------------------------------------------------------------------------
>> 26.3.2. Command-Line Interface
>> [...]
>> Test modules can be specified by file path as well:
>> python -m unittest tests/test_something.py
>> This allows you to use the shell filename completion to specify the
>> test module. The file specified must still be importable as a module.
>> The path is converted to a module name by removing the ‘.py’ and
>> converting path separators into ‘.’
> I didn't know this.
>> According to this, from E:\Projects\mcm, I should be able to type
>> py -m unittest ./test/db/test_manager.py
> Let's process the argument you provide following the above recipe:
> (1) Remove .py
> "./test/db/test_manager"
> (2) Replace / with .
> "..test.db.test_manager"
> Do you see now why
>>  this continues to result in:
> [...]
>>   File "C:\Python34\lib\unittest\loader.py", line 105, in
>>   loadTestsFromName
>>     module = __import__('.'.join(parts_copy))
>> ValueError: Empty module name
> ?

This gets into the same issue you pointed out earlier in the thread.
Thanks for demonstrating how I *should* have applied the docs to my
current question.

> Without the leading ./ it will probably work.

Unfortunately, no:

E:\Projects\mcm>E:\Projects\mcm>py -m unittest test/db/test_manager.py
'E:\Projects\mcm' is not recognized as an internal or external command,
operable program or batch file.

I also tried (Just to try...)

E:\Projects\mcm>E:\Projects\mcm>py -m unittest /test/db/test_manager.py
'E:\Projects\mcm' is not recognized as an internal or external command,
operable program or batch file.

However, if I use the FULL path:

E:\Projects\mcm>py -m unittest e:\Projects\mcm\test\db\test_manager.py
Ran 1 test in 0.000s


all is fine.

>> I believe that I understand Peter's point earlier, but if I am reading
>> the docs correctly, I should be able to do this.

With your help, I have (finally) demonstrated this.

> While I don't think it's a bug you might still file a feature request on
> bugs.python.org.

In retrospect, the only change I would suggest to the cited docs, is
to say "... full file path ..." or "... fully qualified file path ..."
instead of just "... file path ...".


More information about the Tutor mailing list