How to skip/block the before_request call in pytest for Python flask application?

Solution
@app.before_request
def load_user():
    if "user_id" in session:
        g.user = db.session.get(session["user_id"])
from flask import Flask, session

app = Flask(__name__)


@app.before_request
def before_request():
    if "user_id" in session:
        return None  # Let's say we will skip if user_id is present
    print("Before request")


@app.route("/")
def index():
    print("Within index")
    return "Hello World!"
import pytest

from src import app


@pytest.fixture
def client():
    tester = app.test_client()
    yield tester


def test_index_mock_before_request(client, mocker):
    mocker.patch("src.session", {"user_id": None})  # Patch session to include "user_id" so that the before_request would be skipped

    response = client.get('/')
    assert response.status_code == 200


def test_index(client):
    response = client.get('/')
    assert response.status_code == 200
...
# Same as above, just replace the following lines

@app.before_request
def before_request():
    print("Before request")
...
...
# Same as above, just replace the following lines

def test_index_mock_before_request(client, mocker):
    mocker.patch.object(app, "before_request_funcs", {})  # Remove all registered before_request functions so that they wouldn't be run

    response = client.get('/')
    assert response.status_code == 200
...
$ pytest -q -rP
..                                                                                            [100%]
============================================== PASSES ===============================================
__________________________________ test_index_mock_before_request ___________________________________
--------------------------------------- Captured stdout call ----------------------------------------
Within index
____________________________________________ test_index _____________________________________________
--------------------------------------- Captured stdout call ----------------------------------------
Before request
Within index
2 passed in 0.14s