This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest discover does not mention module file must be named with "test_" prefix
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: alex.75, docs@python, zach.ware
Priority: normal Keywords:

Created on 2017-06-23 21:57 by alex.75, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg296740 - (view) Author: Alessandro Piccione (alex.75) Date: 2017-06-23 21:57
1. execute "python -m unittest"
2. Result: 0 test found
3. Change file name from "aaaTest.py" to "test_aaa.py" 
4. execute "python -m unittest"
3. Result: Ran 1 tests in 000.0s

Module file MUST be named using the prefiux "test_".

The page "https://docs.python.org/3/library/unittest.html"
does not mention this MANDATORY rule.

I went to this conclusion because I readed the documentation without find any point about the naming convention of modules and than looking for this specific rule searching "test_" and "test_ " without any result.

Regards,

Alessandro
msg296741 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2017-06-23 22:05
Does this cover what you're looking for?

https://docs.python.org/3/library/unittest.html#cmdoption-unittest-discover-p
msg296742 - (view) Author: Alessandro Piccione (alex.75) Date: 2017-06-23 22:17
If you refer to the -p ("pattern" parameter) I think not.
I have my module named aaaTest.py.
I is is not mentioned that discover look for modules named "test_" for which reason I have to use a pattern?

If you refer to -s ("start-directory" parameter) same thing: for which reason I have to assume my aaaTest.py module is not recognized as a test?
msg297073 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2017-06-27 20:01
This all seems to be covered in https://docs.python.org/3/library/unittest.html#test-discovery

$ cat aaaTest.py 
import unittest


class TestAAA(unittest.TestCase):

    def test_something(self):
        self.assertTrue(True)


if __name__ == '__main__':
    unittest.main()
$ python3 -m unittest discover -v -p "*Test.py"
test_something (aaaTest.TestAAA) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK



As the `--pattern` documentation says, the default pattern is "test*.py" which does not match "aaaTest.py".
msg297074 - (view) Author: Alessandro Piccione (alex.75) Date: 2017-06-27 20:35
You are right.

As the `--pattern` documentation says, the default pattern is "test*.py" which does not match "aaaTest.py".

I had looking for the wrong pattern.

Thanks,

Alex
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 74928
2017-06-27 20:35:24alex.75setstatus: open -> closed
type: behavior
messages: + msg297074

resolution: not a bug
stage: resolved
2017-06-27 20:01:56zach.waresetmessages: + msg297073
2017-06-23 22:17:11alex.75setmessages: + msg296742
2017-06-23 22:05:22zach.waresetnosy: + zach.ware
messages: + msg296741
2017-06-23 21:57:36alex.75create