0

I am trying to skip a function with monkeypatch fixture during request. Is it possible?

from flask import Flask
import functools

app = Flask(__name__)

def some_decorator(view):
    @functools.wraps(view)
    def wrapper():
        return 'hello, wrapper'
    return wrapper

@app.route("/")
@some_decorator
def index():
    return 'hello, world'

def test_monkey_patch(monkeypatch):
    def skip_some_decorator():
        pass

    monkeypatch.setattr('{}.some_decorator'.format(__name__),skip_some_decorator)
    res = app.test_client().get("/")
    assert res.data == b'hello, world'
davidism
  • 121,510
  • 29
  • 395
  • 339
S.aad
  • 518
  • 1
  • 5
  • 22
  • Does this help? https://stackoverflow.com/questions/9702219/how-to-skip-or-ignore-python-decorators – Jon Mar 11 '20 at 14:03
  • 1
    What exactly does `some_decorator` do that you want disabled for the test? In general, you don't want to modify the thing you are actually testing. You can't "skip" the decorator, because it has already been applied. What you are really looking to do is to *undo* the decoration, which isn't in general possible. – chepner Mar 11 '20 at 14:35
  • @chepner `You can't "skip" the decorator, because it has already been applied` made it clear – S.aad Mar 11 '20 at 15:31

0 Answers0