Skip to content

Commit 6e46f15

Browse files
committed
Merge remote-tracking branch 'upstream/master' into jadkik/fix_liveserver_process_termination
2 parents b4b0d38 + 61cb484 commit 6e46f15

17 files changed

+197
-122
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ htmlcov/
1717
.tox/
1818
.coverage
1919
.coverage.*
20-
.cache
20+
.pytest_cache/
21+
.eggs/
2122
coverage.xml
2223
tests/junit.xml
24+
25+
pytest_flask/_version.py

.travis.yml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
language: python
22

3-
branches:
4-
except:
5-
- gh-pages
6-
7-
cache:
8-
directories:
9-
- "${HOME}/virtualenv"
10-
- "${TRAVIS_BUILD_DIR}/.tox"
11-
123
python:
13-
- 2.6
14-
- 2.7
15-
- 3.3
16-
- 3.4
17-
- 3.5
18-
- 3.6
19-
- pypy
4+
- "3.6"
5+
6+
stages:
7+
- test
8+
- name: deploy
9+
if: repo = pytest-dev/pytest-flask AND tag IS present
10+
11+
jobs:
12+
include:
13+
- env: TOXENV=py27
14+
python: '2.7'
15+
- env: TOXENV=py34
16+
python: '3.4'
17+
- env: TOXENV=py35
18+
python: '3.5'
19+
- env: TOXENV=py36
20+
python: '3.6'
21+
- env: TOXENV=py37
22+
python: '3.7'
23+
sudo: required
24+
dist: xenial
2025

21-
matrix:
22-
fast_finish: true
23-
allow_failures:
24-
- python: 3.6
25-
- python: 3.5
26+
- stage: deploy
27+
python: '3.6'
28+
env:
29+
install: pip install -U setuptools setuptools_scm
30+
script: skip
31+
deploy:
32+
provider: pypi
33+
user: nicoddemus
34+
distributions: sdist bdist_wheel
35+
skip_upload_docs: true
36+
password:
37+
secure: lSaCqdifJoDS7qjpAnGgfrvuACEEBBQYDsjtkNlkktIhrZNJi0OjNWNuHN8uDpQSULiOdiQv/bOCAk288Pao341nHznMP3Cu9o+Zgi96dESAwTHx7w+01uzj+nzuRieeYL+Ye9VK0W3A7yu8tTG2GAhuqKCv0bDV7fUKAfySSI+SKTudLt4DHAYLd02tpbmPoHcHRqUSKTtkJKYUaYGM9QGk8p4+2ap006nqiykhiplnAWNLu+xzby7TaFYpA3Yy4x6XWMcdOoTaaBzQHZaGVayT1zR1BfmcOovlIb8sOUQVr6PV/dxC29VTRuyY85S2Rdyw/2Y4viTO5c1omEU/pVzy4RNi4RWboh58WA0kjrwOmb/nLW8AcXNJG9H828dqy8KKdbblTU5guz1oO1Tb2ICLT2z4hQOcZoDkCg3jf54Ee4BYvLOvMH/kNOjNqLA7wjBUzvyWk5OPOIPZ0rozmRwU89VS2kxIhbvtAq0BtmLnIYY3nT5BIrt18FomiINxlgZj6jz2uWGaOPAhcghdjydbGdYs5g2JcUc1B3jvXSyjB+o1l/EJ9OUwCQWIc32XWvOtx/a7pcyrejbKBqQqi5nKF1bvYDM+8VSLEeLTIX1Ie8hModxWp8WPIk+dHBdy8Kb91c4ssOvEkfwHK7cYBdbcn6O0yhiLOxuOO/3Cb3c=
38+
on:
39+
tags: true
40+
repo: pytest-dev/pytest-flask
2641

2742
install:
28-
- pip install tox
29-
- pip install tox-travis
43+
- pip install -U pip
44+
- pip install -U tox setuptools
3045

3146
script:
3247
- tox
33-
- "find ${TRAVIS_BUILD_DIR}/.tox -name log -o -name __pycache__ -type d | xargs -I {} rm -rf {}"
3448

HOWTORELEASE.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Here are the steps on how to make a new release.
2+
3+
1. Create a ``release-VERSION`` branch from ``upstream/master``.
4+
2. Update ``docs/changelog.rst``.
5+
3. Push a branch with the changes.
6+
4. Once all builds pass, push a tag to ``upstream``.
7+
5. Merge the PR.

MANIFEST.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pytest-flask
22
============
33

4-
|PyPI version| |PyPI downloads| |Documentation status|
4+
|PyPI version| |conda-forge version| |Python versions| |Documentation status|
55

66
An extension of `pytest <http://pytest.org/>`__ test runner which
77
provides a set of useful tools to simplify testing and development
@@ -14,7 +14,9 @@ the `PyPI <https://pypi.python.org/pypi/pytest-flask>`__ overview page or
1414
How to start?
1515
-------------
1616

17-
Define your application fixture in ``conftest.py``::
17+
Define your application fixture in ``conftest.py``:
18+
19+
.. code-block:: python
1820
1921
from myapp import create_app
2022
@@ -38,8 +40,12 @@ suggestion.
3840
:target: https://pypi.python.org/pypi/pytest-flask
3941
:alt: PyPi version
4042

41-
.. |PyPI downloads| image:: https://img.shields.io/pypi/dm/pytest-flask.svg
42-
:target: https://pypi.python.org/pypi/pytest-flask
43+
.. |conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/pytest-flask.svg
44+
:target: https://anaconda.org/conda-forge/pytest-flask
45+
:alt: conda-forge version
46+
47+
.. |Python versions| image:: https://img.shields.io/pypi/pyversions/pytest-flask.svg
48+
:target: https://pypi.org/project/pytest-flask
4349
:alt: PyPi downloads
4450

4551
.. |Documentation status| image:: https://readthedocs.org/projects/pytest-flask/badge/?version=latest

docs/changelog.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
Changelog
44
=========
55

6-
Upcoming release
7-
-----------------
6+
7+
Next Release
8+
------------
9+
10+
- Add new ``--live-server-port`` option to select the port the live server will use (`#82`_).
11+
Thanks `@RazerM`_ for the PR.
12+
13+
.. _@RazerM: https://github.com/RazerM
14+
.. _#82: https://github.com/pytest-dev/pytest-flask/pull/82
15+
16+
17+
0.11.0 (compared to 0.10.0)
18+
---------------------------
19+
20+
- Implement deployment using Travis, following in line with many other pytest plugins.
21+
22+
- Allow live server to handle concurrent requests (`#56`_), thanks to
23+
`@mattwbarry`_ for the PR.
824

925
- Fix broken link to pytest documentation (`#50`_), thanks to
1026
`@jineshpaloor`_ for the PR.
@@ -21,8 +37,10 @@ Upcoming release
2137
.. _#43: https://github.com/vitalk/pytest-flask/issues/43
2238
.. _#48: https://github.com/pytest-dev/pytest-flask/pull/48
2339
.. _#50: https://github.com/pytest-dev/pytest-flask/pull/50
40+
.. _#56: https://github.com/pytest-dev/pytest-flask/pull/56
2441
.. _@danstender: https://github.com/danstender
2542
.. _@jineshpaloor: https://github.com/jineshpaloor
43+
.. _@mattwbarry: https://github.com/mattwbarry
2644
.. _@steenzout: https://github.com/steenzout
2745

2846

docs/features.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ example, in your project’s ``pytest.ini`` file)::
157157

158158
.. note::
159159

160-
Your **should manually start** live server after you finish your application
160+
You **should manually start** live server after you finish your application
161161
configuration and define all required routes:
162162

163163
.. code:: python
@@ -174,6 +174,17 @@ example, in your project’s ``pytest.ini`` file)::
174174
assert b'got it' in res.read()
175175
176176
177+
``--live-server-port`` - use a fixed port
178+
`````````````````````````````````````````
179+
180+
By default the server uses a random port. In some cases it is desirable to run
181+
the server with a fixed port. You can use ``--live-server-port`` (for example,
182+
in your project's ``pytest.ini`` file)::
183+
184+
[pytest]
185+
addopts = --live-server-port=5000
186+
187+
177188
``request_ctx`` - request context
178189
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179190

pytest_flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
__version__ = "0.10.0"
4+
from ._version import version as __version__

pytest_flask/fixtures.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import logging
1010

1111
try:
12-
from urllib2 import urlopen
12+
from urllib2 import URLError, urlopen
1313
except ImportError:
14+
from urllib.error import URLError
1415
from urllib.request import urlopen
1516

1617
from flask import _request_ctx_stack
@@ -37,7 +38,7 @@ def login(self, email, password):
3738
return self.client.post(url_for('login'), data=credentials)
3839
3940
def test_login(self):
40-
assert self.login('vital@example.com', 'pass').status_code == 200
41+
assert self.login('foo@example.com', 'pass').status_code == 200
4142
4243
"""
4344
if request.cls is not None:
@@ -61,7 +62,7 @@ def __init__(self, app, port, clean_stop=False):
6162
def start(self):
6263
"""Start application in a separate process."""
6364
def worker(app, port):
64-
app.run(port=port, use_reloader=False)
65+
app.run(port=port, use_reloader=False, threaded=True)
6566
self._process = multiprocessing.Process(
6667
target=worker,
6768
args=(self.app, self.port)
@@ -76,7 +77,7 @@ def worker(app, port):
7677
try:
7778
urlopen(self.url())
7879
timeout = 0
79-
except:
80+
except URLError:
8081
timeout -= 1
8182

8283
def url(self, url=''):
@@ -114,10 +115,10 @@ def _rewrite_server_name(server_name, new_port):
114115

115116

116117
@pytest.fixture(scope='function')
117-
def live_server(request, app, monkeypatch):
118+
def live_server(request, app, monkeypatch, pytestconfig):
118119
"""Run application in a separate process.
119120
120-
When the ``live_server`` fixture is applyed, the ``url_for`` function
121+
When the ``live_server`` fixture is applied, the ``url_for`` function
121122
works as expected::
122123
123124
def test_server_is_up_and_running(live_server):
@@ -128,11 +129,14 @@ def test_server_is_up_and_running(live_server):
128129
assert res.code == 200
129130
130131
"""
131-
# Bind to an open port
132-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
133-
s.bind(('', 0))
134-
port = s.getsockname()[1]
135-
s.close()
132+
port = pytestconfig.getvalue('live_server_port')
133+
134+
if port == 0:
135+
# Bind to an open port
136+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
137+
s.bind(('', 0))
138+
port = s.getsockname()[1]
139+
s.close()
136140

137141
# Explicitly set application ``SERVER_NAME`` for test suite
138142
# and restore original value on test teardown.

0 commit comments

Comments
 (0)