Skip to content

Commit d7a347b

Browse files
committed
Add appdir fixture to simplify testing
1 parent 7f2e88d commit d7a347b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
# -*- coding: utf-8 -*-
33
import pytest
44

5+
from textwrap import dedent
56
from flask import Flask, jsonify
67

78

9+
pytest_plugins = 'pytester'
10+
11+
812
@pytest.fixture
913
def app():
1014
app = Flask(__name__)
@@ -19,3 +23,28 @@ def ping():
1923
return jsonify(ping='pong')
2024

2125
return app
26+
27+
28+
@pytest.fixture
29+
def appdir(testdir):
30+
app_root = testdir.tmpdir
31+
test_root = app_root.mkdir('tests')
32+
33+
def create_test_module(code, filename='test_app.py'):
34+
f = test_root.join(filename)
35+
f.write(dedent(code), ensure=True)
36+
return f
37+
38+
testdir.create_test_module = create_test_module
39+
40+
testdir.create_test_module('''
41+
import pytest
42+
43+
from flask import Flask
44+
45+
@pytest.fixture
46+
def app():
47+
app = Flask(__name__)
48+
return app
49+
''', filename='conftest.py')
50+
return testdir

0 commit comments

Comments
 (0)