-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Better document -k partial matching #7610
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
Better document -k partial matching #7610
Conversation
doc/en/example/markers.rst
Outdated
| You can use ``and``, ``or``, ``not`` and parentheses. | ||
|
|
||
| .. note:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a regular paragraph, not a note.
doc/en/example/markers.rst
Outdated
| ``-k`` option will match not only function names but also `function attributes <https://www.python.org/dev/peps/pep-0232/>`_ . | ||
| For example, every function has attributes such as ``__call__`` by default, | ||
| and some libraries like `hypothesis <https://github.com/HypothesisWorks/hypothesis>`_ attach additional attributes to functions. | ||
| So if you specify such a keyword, let's say ``-k "__call__"``, then ``-k`` will match all functions in the scope, because all functions have ``__call__`` attributes. | ||
| Unfortunetelly you can't controll this behavior in current version, so please keep it in your mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should definitely lay out what is included in -k. Below is a suggestion with these differences:
- Added some more things which are matched against.
- Removed the reference to the ancient PEP, I don't think it adds too much.
- Removed the
__call__example. Normally__call__is not found in a function's__dict__so is not matched. Maybe Hypothesis does something more customized, but I think it will be confusing for other users. - Removed the "unfortunately" sentence. At least in pytest the behavior is more of a feature than a bug. I think just explaining the behavior is enough.
| ``-k`` option will match not only function names but also `function attributes <https://www.python.org/dev/peps/pep-0232/>`_ . | |
| For example, every function has attributes such as ``__call__`` by default, | |
| and some libraries like `hypothesis <https://github.com/HypothesisWorks/hypothesis>`_ attach additional attributes to functions. | |
| So if you specify such a keyword, let's say ``-k "__call__"``, then ``-k`` will match all functions in the scope, because all functions have ``__call__`` attributes. | |
| Unfortunetelly you can't controll this behavior in current version, so please keep it in your mind. | |
| In addition to the test's name, ``-k`` also matches the names of the test's parents (usually, the name of the file and class it's in), attributes set on the test function, markers applied to it or its parents and any :attr:`extra keywords <_pytest.nodes.Node.extra_keyword_matches>` explicitly added to it or its parents. |
|
@bluetech Thank you for reviewing, and sorry for my misunderstanding. All you pointed out makes sense, I applied your comments. |
bluetech
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM now.
nicoddemus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ikedaosushi and @bluetech !
Closes #7546.
To be honest, I'm not sure if this description is the best, I would be happy if you can modify it freely.