Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest -h shows a flag -s but it doesn't work #85425

Closed
FarisChugthai mannequin opened this issue Jul 9, 2020 · 4 comments
Closed

unittest -h shows a flag -s but it doesn't work #85425

FarisChugthai mannequin opened this issue Jul 9, 2020 · 4 comments
Labels
3.8 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@FarisChugthai
Copy link
Mannequin

FarisChugthai mannequin commented Jul 9, 2020

BPO 41253
Nosy @ericvsmith, @serhiy-storchaka, @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-07-10.21:13:26.680>
created_at = <Date 2020-07-09.04:37:30.659>
labels = ['3.8', 'type-bug', 'tests', 'invalid']
title = "unittest -h shows a flag -s but it doesn't work"
updated_at = <Date 2020-07-10.21:13:26.677>
user = 'https://bugs.python.org/FarisChugthai'

bugs.python.org fields:

activity = <Date 2020-07-10.21:13:26.677>
actor = 'eric.smith'
assignee = 'none'
closed = True
closed_date = <Date 2020-07-10.21:13:26.680>
closer = 'eric.smith'
components = ['Tests']
creation = <Date 2020-07-09.04:37:30.659>
creator = 'Faris Chugthai'
dependencies = []
files = []
hgrepos = []
issue_num = 41253
keywords = []
message_count = 4.0
messages = ['373372', '373373', '373376', '373484']
nosy_count = 4.0
nosy_names = ['eric.smith', 'serhiy.storchaka', 'xtreak', 'Faris Chugthai']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41253'
versions = ['Python 3.8']

@FarisChugthai
Copy link
Mannequin Author

FarisChugthai mannequin commented Jul 9, 2020

I'm not 100% sure what's happening here but running:

python -m unittest -h

shows a flag -s as does

python -m unittest discover -h.

When run as:

python -m unittest discover -s test

the command runs correctly but when run as

python -m unittest -s test

the command fails.

$ python -m unittest -s test  
                      
usage: python -m unittest [-h] [-v] [-q] [--locals] [-f]                                [-c] [-b] [-k TESTNAMEPATTERNS]                               [tests [tests ...]

       
python -m unittest: error: unrecognized arguments: -s

Which I believe to be a bug as the help generated by the discover subcommand indicates that the flag -s should be recognized.

@FarisChugthai FarisChugthai mannequin added 3.8 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Jul 9, 2020
@serhiy-storchaka
Copy link
Member

Where do you see option -s?

@tirkarthi
Copy link
Member

The -s option shown in python3 -m unittest -h is grouped under help for discover. Options for a discover command don't necessarily apply to the unittest command itself.

$ python3 -m unittest -h
usage: python3 -m unittest [-h] [-v] [-q] [--locals] [-f] [-c] [-b]
                           [-k TESTNAMEPATTERNS]
                           [tests [tests ...]]

positional arguments:
tests a list of any number of test modules, classes and test
methods.

optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose output
-q, --quiet Quiet output
--locals Show local variables in tracebacks
-f, --failfast Stop on first fail or error
-c, --catch Catch Ctrl-C and display results so far
-b, --buffer Buffer stdout and stderr during tests
-k TESTNAMEPATTERNS Only run tests which match the given substring

Examples:
python3 -m unittest test_module - run tests from test_module
python3 -m unittest module.TestClass - run tests from module.TestClass
python3 -m unittest module.Class.test_method - run specified test method
python3 -m unittest path/to/test_file.py - run tests from test_file.py

usage: python3 -m unittest discover [-h] [-v] [-q] [--locals] [-f] [-c] [-b]
[-k TESTNAMEPATTERNS] [-s START]
[-p PATTERN] [-t TOP]

optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose output
-q, --quiet Quiet output
--locals Show local variables in tracebacks
-f, --failfast Stop on first fail or error
-c, --catch Catch Ctrl-C and display results so far
-b, --buffer Buffer stdout and stderr during tests
-k TESTNAMEPATTERNS Only run tests which match the given substring
-s START, --start-directory START
Directory to start discovery ('.' default)
-p PATTERN, --pattern PATTERN
Pattern to match tests ('test*.py' default)
-t TOP, --top-level-directory TOP
Top level directory of project (defaults to start
directory)

For test discovery all test modules must be importable from the top level
directory of the project.

@ericvsmith
Copy link
Member

This appears to just be a misunderstanding: -s is a flag to "unittest discover", not to "unittest" itself. I think this is clear from the help text, so I'm closing this.

If I'm incorrect, let me know.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants