-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
plugin: loggingrelated to the logging builtin pluginrelated to the logging builtin plugintopic: rewriterelated to the assertion rewrite mechanismrelated to the assertion rewrite mechanismtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Description
What's the problem this feature will solve?
The pytest_assertion_pass hook provides the test item and lineno, but sometimes the assertion line comes from an utility function/fixture in a different module and not from the test body itself.
Also it would be nice to be able to log from the logger of the module where the assertion code is, as if the logging call was hardcoded together with the assertion.
Describe the solution you'd like
Add a new module argument to pytest_assertion_pass.
Usage example:
def pytest_assertion_pass(item, module, lineno, orig, expl):
logging.getLogger(module).info(f"Assertion passed for {orig}")This could be relatively easily accomplished by adding an argument in the rewrite.py module:
hook_call_pass = ast.Expr(
self.helper(
"_call_assertion_pass",
ast.Name("__name__", ast.Load()) # <- module name
ast.Num(assert_.lineno),
ast.Str(orig),
fmt_pass,
)
)Alternative Solutions
Additional context
If you feel this is a feature worth having and the solution is fine, I would be more than happy to open a PR
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
plugin: loggingrelated to the logging builtin pluginrelated to the logging builtin plugintopic: rewriterelated to the assertion rewrite mechanismrelated to the assertion rewrite mechanismtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature