-
Notifications
You must be signed in to change notification settings - Fork 98
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
skip_if decorator for monitors #339
Comments
Hello @rennerocha Thank you for the explanation and the suggested solution. Just for my better understanding, can you please explain a bit more that if we can achieve this by using Thank you. |
Wouldn't it be better to just disable this monitor at all for Spiders that may yield 0 items? The only advantage that I see to the |
This can't be achieved using |
If the spider yield more than 1 item, I do want the monitor to be executed. But the spider may eventually yield 0 items so I don't want the monitors to be executed in that case. I can't simply disable it. |
@VMRuiz When I thought about the If not implemented, we still have the problem with the |
If something is going to be implemented in Spidermon, #366 looks much more important with real use cases than this issue. |
Maybe in just focusing too much in a technicism here but, what is the difference between skippipng a monitor and not executing it? Why would you want to have a monitor that will always be ok?
This user case looks much more interesting. |
I am not sure if you really understood the use-case. One thing is disable a monitor, so it will never be executed. Other scenario is, if a certain condition is met (i.e. no items returned, a certain number of errors happen, a finished reason is something different for a certain value, etc) the monitor is not executed (skipped), but if the condition is not met, the monitor is executed. These conditions are defined in runtime, so we can not disable the monitor beforehand. In the end, monitors are just like test cases, so the definition for skipping a test in pytest documentation is valid here (replace
|
I've been thinking about it, and after the last consideration, I'm starting to understand more about what Muhammad has started implementing at #384. It would be nice to have multiple options: to disable full monitor classes, specific But if we go away with implementing it as a decorator, we could add it as this new
That way, we could add skip rules for built-in monitors without having to extend them. This is mostly @VMRuiz and @shafiq-muhammad's idea as I understand it but I wanted to post it here for context and to say that I like it 😅 |
Do we still need this decorator or is it just enough with the current |
@VMRuiz I think For reference, we talked about some details in this (private) slack thread about how to use it a few months ago, but the bottom line was that:
|
This came from a real use case:
FieldCoverageMonitor
requires that we have at least one item returned, or else it will fail. However there are situation when we allow a spider to return no items. Think about a real estate website searching for locations in a certain neighborhood, sometimes even with the right code, we don't have any result, so we should not fail our monitors.This is not possible with our built-in monitors, and the solution is create a new custom monitor, base in a built-in monitor that implements this check before doing the test.
pytest
library has askipif
decorator (https://docs.pytest.org/en/6.2.x/skipping.html#id1) where you can set some rules and if these rules are not met, the test are not executed. We could consider to add something like that in Spidermon so we can decide if we want to execute or skip a test considering a condition (check a stat value could be enough).Some options to accomplish that:
skipif
decorator that can be applied to aMonitorSuite
class, so the entire suite will not be executed whether the condition is not met. This looks simpler, as we can use our existing built-in monitors as-it-is now and the control isskipif
decorator for thetest_
methods, so that method is not executed whether the condition is met. This has the drawback that when we want to use a built-in monitor, we will need to create a custom monitor just to add the decoratorOpening this issue to get more ideas and suggestions if this is a good idea and if so, what is the best solution for that.
The text was updated successfully, but these errors were encountered: