Skip to content

Conversation

@ikedaosushi
Copy link
Contributor

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.

  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.

You can use ``and``, ``or``, ``not`` and parentheses.

.. note::
Copy link
Member

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.

Comment on lines 204 to 208
``-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.
Copy link
Member

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.
Suggested change
``-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.

@ikedaosushi
Copy link
Contributor Author

@bluetech Thank you for reviewing, and sorry for my misunderstanding. All you pointed out makes sense, I applied your comments.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM now.

Copy link
Member

@nicoddemus nicoddemus left a 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 !

@nicoddemus nicoddemus merged commit 84c4b64 into pytest-dev:master Aug 4, 2020
@ikedaosushi ikedaosushi deleted the GH-7546_better-document-k-flag branch August 5, 2020 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better document -k partial matching and what 'keyword' means

3 participants