-
Notifications
You must be signed in to change notification settings - Fork 14
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
Reintroduce activate(f)
and deactivate()
#135
Reintroduce activate(f)
and deactivate()
#135
Conversation
These were dropped in the initial v0.8 release (see PR#119) but were being used in the wild so this PR brings them back, but with documentation warning about the downsides of their usage.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
+ Coverage 97.91% 98.03% +0.12%
==========================================
Files 6 6
Lines 144 153 +9
==========================================
+ Hits 141 150 +9
Misses 3 3 ☔ View full report in Codecov by Sentry. |
""" | ||
Mocking.deactivate() -> Nothing | ||
|
||
Disable `@mock` call sites to only call the original function. | ||
|
||
!!! note | ||
It is not usually necessary to call this function directly. | ||
Instead it is recommended to simply call `Mocking.activate()` in `test/runtests.jl` to | ||
activate `@mock` call sites for the duration of the test suite. | ||
""" | ||
function deactivate() | ||
# Avoid redefining `_activated` when it's already set appropriately | ||
Base.invokelatest(activated) && @eval _activated(::Int) = false | ||
return nothing | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need deactivate
? Unless you also require this for your code base it's probably best to avoid re-introducing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just for implementing (and testing) activate(f)
, so perhaps we should delete the doc-string and name this _deactivate()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be good with me.
Just to double check: what is the problem with doing a removal on all of the |
I think there are two reasons we prefer
|
A quick look at internal issues, and i can't find a reference for this so i might be misremembering 🤔 i'll need to check more carefully next week (And if most tests need Mocking, not paying the recompilation cost of enabling/disabling will be more performant) i think the "reduce global state" does matter 🤔 I suppose an alternative is to just have every testitem that needs it call |
If this is a concern it should be possible to improve performance on mocked calls where there are no applied patches. I've been prioritizing performance when Mocking is not activated to date. |
Okay, i compared running our whole test suite under |
These were dropped in the initial v0.8 release
(see PR#119) but were being used in the wild so
this PR brings them back, but with documentation
warning about the downsides of their usage.
As mentioned at #119 (comment)
(Originally added in #102)