Bird
0
0

You wrote this retry decorator but it does not retry on failure. What is the bug?

medium📝 Debug Q14 of 15
Selenium Python - Advanced Patterns
You wrote this retry decorator but it does not retry on failure. What is the bug?
def retry(func):
    def wrapper():
        for _ in range(3):
            try:
                func()
            except Exception:
                continue
    return wrapper
AThe decorator is missing the @functools.wraps(func) call
BThe except block should raise the exception instead of continue
CThe loop should be a while loop instead of for loop
DThe function does not return the result or stop retrying on success
Step-by-Step Solution
Solution:
  1. Step 1: Check retry logic

    The wrapper calls func() but never returns its result or breaks loop on success.
  2. Step 2: Effect of missing return

    Without return, wrapper always completes loop and returns None, so retry never stops on success.
  3. Final Answer:

    The function does not return the result or stop retrying on success -> Option D
  4. Quick Check:

    Missing return causes always 3 retries even on success [OK]
Quick Trick: Always return on success to stop retries [OK]
Common Mistakes:
  • Not returning function result inside try
  • Misusing continue in except block
  • Ignoring decorator metadata preservation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes