forked from pytest-dev/pytest-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·183 lines (138 loc) · 4.94 KB
/
setup.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
pytest-flask
============
A set of `pytest <https://docs.pytest.org>`_ fixtures to test Flask
extensions and applications.
Features
--------
Plugin provides some fixtures to simplify app testing:
- ``client`` - an instance of ``app.test_client``,
- ``client_class`` - ``client`` fixture for class-based tests,
- ``config`` - the application config,
- ``live_server`` - runs an application in the background (useful for tests
with `Selenium <http://www.seleniumhq.org>`_ and other headless browsers),
- ``request_ctx`` - the request context,
- ``accept_json``, ``accept_jsonp``, ``accept_any`` - accept headers
suitable to use as parameters in ``client``.
To pass options to your application use the ``pytest.mark.options`` marker:
.. code:: python
@pytest.mark.options(debug=False)
def test_app(app):
assert not app.debug, 'Ensure the app not in debug mode'
During tests execution the request context has been pushed, e.g. ``url_for``,
``session`` and other context bound objects are available without context
managers:
.. code:: python
def test_app(client):
assert client.get(url_for('myview')).status_code == 200
Response object has a ``json`` property to test a view that returns
a JSON response:
.. code:: python
@api.route('/ping')
def ping():
return jsonify(ping='pong')
def test_api_ping(client):
res = client.get(url_for('api.ping'))
assert res.json == {'ping': 'pong'}
If you want your tests done via Selenium or other headless browser use
the ``live_server`` fixture. The server’s URL can be retrieved using
the ``url_for`` function:
.. code:: python
from flask import url_for
@pytest.mark.usefixtures('live_server')
class TestLiveServer:
def test_server_is_up_and_running(self):
res = urllib2.urlopen(url_for('index', _external=True))
assert b'OK' in res.read()
assert res.code == 200
Quick Start
-----------
To start using a plugin define your application fixture in ``conftest.py``:
.. code:: python
from myapp import create_app
@pytest.fixture
def app():
app = create_app()
return app
Install the extension with dependencies and run your test suite:
.. code:: bash
$ pip install pytest-flask
$ py.test
Documentation
-------------
The latest documentation is available at
http://pytest-flask.readthedocs.org/en/latest/.
Contributing
------------
Don’t hesitate to create a `GitHub issue
<https://github.com/vitalk/pytest-flask/issues>`_ for any **bug** or
**suggestion**.
"""
import io
import os
import re
from setuptools import setup
from setuptools import find_packages
def read(*parts):
"""Reads the content of the file located at path created from *parts*."""
try:
return io.open(os.path.join(*parts), 'r', encoding='utf-8').read()
except IOError:
return ''
requirements = read('requirements', 'main.txt').splitlines() + ['pytest']
tests_require = []
extras_require = {
'docs': read('requirements', 'docs.txt').splitlines(),
'tests': tests_require
}
setup(
name='pytest-flask',
# Versions should comply with PEP440, and automatically obtained from tags
# thanks to setuptools_scm
use_scm_version={"write_to": "pytest_flask/_version.py"},
setup_requires=["setuptools-scm"],
author='Vital Kudzelka',
author_email='[email protected]',
url='https://github.com/vitalk/pytest-flask',
project_urls={
"Source": "https://github.com/pytest-dev/pytest-flask",
"Tracker": "https://github.com/pytest-dev/pytest-flask/issues",
},
description='A set of py.test fixtures to test Flask applications.',
long_description=__doc__,
license='MIT',
packages=find_packages(exclude=['docs', 'tests']),
zip_safe=False,
platforms='any',
install_requires=requirements,
tests_require=tests_require,
extras_require=extras_require,
keywords='pytest flask testing',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Plugins',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Testing',
'Topic :: Software Development :: Libraries :: Python Modules',
],
# The following makes a plugin available to pytest
entry_points={
'pytest11': [
'flask = pytest_flask.plugin',
]
},
)