File: conftest.py

package info (click to toggle)
pytest-flask 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: python: 553; makefile: 161; sh: 5
file content (54 lines) | stat: -rwxr-xr-x 1,069 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
from textwrap import dedent

import pytest
from flask import Flask
from flask import jsonify

from pytest_flask.fixtures import mimetype

pytest_plugins = "pytester"


@pytest.fixture(scope="session")
def app():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "42"

    @app.route("/")
    def index():
        return app.response_class("OK")

    @app.route("/ping")
    def ping():
        return jsonify(ping="pong")

    return app


@pytest.fixture
def appdir(testdir):
    app_root = testdir.tmpdir
    test_root = app_root.mkdir("tests")

    def create_test_module(code, filename="test_app.py"):
        f = test_root.join(filename)
        f.write(dedent(code), ensure=True)
        return f

    testdir.create_test_module = create_test_module

    testdir.create_test_module(
        """
        import pytest

        from flask import Flask

        @pytest.fixture(scope='session')
        def app():
            app = Flask(__name__)
            return app
    """,
        filename="conftest.py",
    )
    return testdir