-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
@test_deprecated
macro
#20348
Comments
💯 I've been wanting something like this for quite a while. It will also (hopefully) help ensure that deprecations are done properly. It's easy to mess those up, so having a way to check would be fantastic. |
I think ideally this should hook slightly deeper to the depwarn system to actually check if a depwarn is triggered. Conditional changing to test/test_warn/test_error has the issue that it can be confused with other warning/errors. |
Sure, even better integration would obviously be even better. |
as I said there, if this is going to be testing for 3 different possibilities then these tests should be put in a file that gets run with all 3 settings, depwarn_exec or similar like we do for bounds checking |
I don't get this. Every time we add a deprecation we should test that the thing is in fact deprecated? |
@JeffBezanson I see it as just an added a safeguard against misspecifying, omitting, or failing to remove a deprecation. As an aside, we could have |
I think it's mostly because we've had many cases where the deprecation doesn't actually work because there's no test for it. Adding a test macro that suppresses the depwarn can make sure such thing can still be tested without printing pages of depwarn/slow down due to backtrace collection in depwarn. I don't really think we need to make sure each depwarn behaves correctly at all three cmdline settings although a independent test for that can be useful. |
In my case, it was mostly so that I could write tests now that will fail when we remove the deprecation, reminding me (or whoever) to actually go fix the tests to test that the post-deprecation behavior is correct. Otherwise you have some todo in a test file that will be ignored for eternity. |
A lot of deprecations get written incorrectly and not fixed until some package breaks because of it. With PkgEval completely freezing and not finishing for the whole month, we're not catching these systematically right now. |
The And 💯 for testing deprecations! Too many bugs discovered too late... |
So, ideally, we could do a single test run that tests that the expression does in fact trigger a deprecation warning and that the deprecated behavior is the expected one. Since we generally already had tests for deprecated functions in place, we could just leave a few around and they would automatically get cleaned out when the deprecation is deleted (since otherwise tests fail). |
I'm in favor of being able to test deprecations. An example of an incorrect deprecation that needed fixing: #19375 |
Regarding this, when something is deprecated perhaps we can move the existing tests for it (or at least a couple) to something like a test/deprecated.jl rather than leaving them in the same place. (Is the latter what you meant?) That would make housekeeping easier when deprecations are removed. |
Well, in this case, unlike with deprecations which will be deleted, the tests will remain when the deprecations are deleted but they'll need to be updated, so I'd rather leave them in their place. |
I just stumbled across this issue. It should be really easy to sort this out once #24490 is merged - the depwarn now comes out as a structured log record including attaching the caller as a Regarding the behavior depending on the value of
I'm assuming that performance is the reason for |
Note that in the 1.x series we may want to have |
Right, that's an interesting point about having a But not to derail this issue - more on-topic, I've now implemented a @test_deprecated num2hex(1)
@test num2hex(1) == "0000000000000001" Another option is to have an analog of @test @deprecated(num2hex(1)) == "0000000000000001" A further more opinionated option would be to require that the test expression return true, in addition to testing that a depwarn is generated: @test_deprecated num2hex(1) == "0000000000000001" Finally, we can do it like @test @test_deprecated(num2hex(1)) == "0000000000000001" In the process of writing the above list, I've come to the conclusion that the
|
Perhaps a separate issue about changing |
Agreed. See #24829 for |
This is addressed now that #24490 is merged. The only caveat I've found is that the use of
doesn't actually work until we remove |
Someone with committer permissions will have to close this for me ;-) |
Thanks @c42f! :) |
See discussion here: https://github.com/JuliaLang/julia/pull/20330/files#r98575767. I wanted to test that something was deprecated, which is complicated by the fact that the behavior of deprecation can be changed by the
--depwarn={no|yes|error}
flag tojulia
. My solution there was to checkBase.JLOptions().depwarn
and do different tests depending on that value. We could have a@test_deprecated
macro that generates the correct underlying test depending on that flag: for--depwarn=no
it emits a standard test to check that the deprecation definition works, for--depwarn=yes
it emits@test_warn "deprecated"
test to make sure that the deprecation warning is emitted correctly, and for--depwarn=error
it checks that the given expression raises anErrorException
with the word "deprecated" in its message. One of the major benefits of testing for this is so that when you delete a deprecation, you can't forget to update the tests to check for an unconditional error, which is what I originally wanted to do.The text was updated successfully, but these errors were encountered: