Allow disabling assertion rewriting at a function level #12610
Labels
topic: rewrite
related to the assertion rewrite mechanism
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
Background
I was working on a function decorated with
numba.jit(nopython=True)
containing an assert statement. The test fails with numba errors, pointing to the assert statement, even though the logic is correct.Example:
What's the problem this feature will solve?
pytest assert rewriting deals with dumping and reading the bytecode - something numba interferes with too! This causes problems while running numba-decorated functions.
Describe the solution you'd like
The current solutions are:
--assert=plain
.PYTEST_DONT_REWRITE
in the docstring.While (2) is better than (1), it requires manual intervention and edits to each of the modules containing any jitted functions and such,
The ideal solution would be to auto-disable pytest rewriting at a function level.
That is, on finding a jitted function, pytest can skip rewriting only that. The remaining all tests in a module can still have rich asserts.
Alternative Solutions
My current solution has been to patch
rewrite.AssertionRewriter.run
. I modified the part where we accessast.FunctionDef
etc., to check thenode.decorator_list
and see if is using any numba decorators. If anopython=True
function has been found, I skip rewriting all asserts at the function level. Remaining logic stays the same.The text was updated successfully, but these errors were encountered: