-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
An easier way to have test cases in built-in functions #11388
Comments
as pytest is doing certain tasks in unpacking the method to call, is not immediately clear if this is safe to do in general unfortunately definition collection is not yet part of the collection tree else the code could be simplified to making a own Definition and have pytest handle the rest |
Sounds like I'm stuck with the Is there something I can do to investigate if this is safe to use |
@joankaradimov for now we might be able to get away with a opt in for allowing built-ins as tests |
Thanks! I can make a PR for that. Is an additional command line argument sufficient? I can document it in the Any other input? |
I believe a option for the config file fit's better as its always needed when it's needed |
As suggested in #11450 (reply in thread) (which was marked as a duplicate of this one), I'd add that for at least one use-case (collecting doctests), just using At least numpy ufuncs do not --- copying from scipy/scipy_doctest#99 (comment):
So it would be great if there's a hook or a way to pass a predicate. A (possibly tangentially) related issue is that collecting doctests from compiled modules fails with
(#11450 has a proper repro) |
I'd like to suggest that calls to inspect.isfunction are replaced with
inspect.isroutine
.What's the problem this feature will solve?
I'm trying to test some native code functions I have written in Cython. Those are either coming from
.pxd
files or arecdef
functions in.pyx
files. These are not visible to Python code. They can only be called from Cython functions (which are built-in functions).Describe the solution you'd like
I'd like to add a
conftest.py
file which defines in itspytest_collect_file
how to load a Cython test module and then writetest_*
functions in Cython which call the said native functions.Alternative Solutions
It is currently impossible to have a
test_*
function be a built-in function. It fails the check forinspect.isfunction
defined in src/_pytest/python.py. As a workaround I copy-paste the entirepytest_pycollect_makeitem
and replace itsisfunction
checks withisroutine
checks. This is enough of a workaround to get my test cases loaded.Additional context
It's unfortunate that I have to copy-paste library code. This goes against the whole idea of having hooks. One solution is to add new hooks. Another is to just allow a wider range of callables to be detected as test functions.
The text was updated successfully, but these errors were encountered: