Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- name: Build and Check Package
uses: hynek/build-and-inspect-python-package@v1.5
uses: hynek/build-and-inspect-python-package@v3.0.2

deploy:
needs: package
Expand All @@ -30,16 +30,16 @@ jobs:
contents: write # For tag and release notes.

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- name: Download Package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v8
with:
name: Packages
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.5
uses: pypa/gh-action-pypi-publish@v1.14.3

- name: Push tag
run: |
Expand All @@ -49,7 +49,7 @@ jobs:
git push origin ${{ github.event.inputs.version }}

- name: GitHub Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v3
with:
files: dist/*
tag_name: ${{ github.event.inputs.version }}
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
- name: Build and Check Package
uses: hynek/build-and-inspect-python-package@v1.5
uses: hynek/build-and-inspect-python-package@v3.0.2

test:

Expand All @@ -32,19 +32,19 @@ jobs:
fail-fast: false
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest]
os: [ubuntu-24.04, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- name: Download Package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v8
with:
name: Packages
path: dist

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}

Expand Down
26 changes: 12 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-byte-order-marker
- id: fix-byte-order-marker
- id: trailing-whitespace
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: check-yaml
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.14.0
- repo: https://github.com/PyCQA/isort
rev: 9.0.2
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py3-plus]
- repo: https://github.com/psf/black
rev: 24.10.0
- id: isort
args: [--profile=black, --force-single-line-imports, --src=src]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.10.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
rev: 7.4.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
- repo: local
hooks:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
entry: rst-lint
files: ^(RELEASING.rst|README.rst)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
rev: v2.4.0
hooks:
- id: autoflake
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
rev: v2.4.0
hooks:
- id: mypy
files: ^(src/|tests/)
1 change: 0 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mock
pylint
coverage
pytest-pep8
mypy
1 change: 0 additions & 1 deletion src/pytest_flask/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from pytest import Config as _PytestConfig


_PytestScopeName = Literal["session", "package", "module", "class", "function"]


Expand Down
2 changes: 1 addition & 1 deletion src/pytest_flask/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
import socket
from typing import Any
from typing import cast
from typing import Generator
from typing import cast

import pytest
from flask import Flask as _FlaskApp
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_flask/live_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import time
from multiprocessing import Process
from typing import Any
from typing import cast
from typing import Protocol
from typing import Union
from typing import cast

import pytest

Expand Down
8 changes: 4 additions & 4 deletions src/pytest_flask/plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
"""
A py.test plugin which helps testing Flask applications.
A py.test plugin which helps testing Flask applications.

:copyright: (c) by Vital Kudzelka
:license: MIT
:copyright: (c) by Vital Kudzelka
:license: MIT
"""

from typing import Any
from typing import List
from typing import Protocol
Expand All @@ -25,7 +26,6 @@
from .fixtures import live_server
from .pytest_compat import getfixturevalue


_Response = TypeVar("_Response")


Expand Down
57 changes: 18 additions & 39 deletions tests/test_live_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from flask import url_for


pytestmark = pytest.mark.skipif(not hasattr(os, "fork"), reason="needs fork")


Expand Down Expand Up @@ -35,44 +34,38 @@ def test_set_application_server_name(self, live_server):
)

def test_rewrite_application_server_name(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest
@pytest.mark.options(server_name='example.com:5000')
def test_a(live_server):
assert live_server.app.config['SERVER_NAME'] == \\
'example.com:%d' % live_server.port
"""
)
""")

result = appdir.runpytest("-v", "-o", "live_server_scope=function")
result.stdout.fnmatch_lines(["*PASSED*"])
assert result.ret == 0

def test_prevent_starting_live_server(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

def test_a(live_server):
assert live_server._process is None
"""
)
""")

result = appdir.runpytest("-v", "--no-start-live-server")
result.stdout.fnmatch_lines(["*passed*"])
assert result.ret == 0

def test_start_live_server(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

def test_a(live_server):
assert live_server._process
assert live_server._process.is_alive()
"""
)
""")
result = appdir.runpytest("-v", "--start-live-server")
result.stdout.fnmatch_lines(["*passed*"])
assert result.ret == 0
Expand Down Expand Up @@ -103,8 +96,7 @@ def mocked_stop_cleanly(*args, **kwargs):

monkeypatch.setattr(LiveServer, "_stop_cleanly", mocked_stop_cleanly)

appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

from flask import url_for
Expand All @@ -119,8 +111,7 @@ def index():
res = client.get(url_for('index', _external=True))
assert res.status_code == 200
assert b'got it' in res.data
"""
)
""")
args = [] if clean_stop else ["--no-live-server-clean-stop"]
result = appdir.runpytest_inprocess("-v", "--no-start-live-server", *args)
result.stdout.fnmatch_lines("*1 passed*")
Expand All @@ -130,8 +121,7 @@ def index():
assert stop_cleanly_result == []

def test_add_endpoint_to_live_server(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

from flask import url_for
Expand All @@ -146,16 +136,14 @@ def new_endpoint():
res = client.get(url_for('new_endpoint', _external=True))
assert res.status_code == 200
assert b'got it' in res.data
"""
)
""")
result = appdir.runpytest("-v", "--no-start-live-server")
result.stdout.fnmatch_lines(["*passed*"])
assert result.ret == 0

@pytest.mark.skip("this test hangs in the original code")
def test_concurrent_requests_to_live_server(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

from flask import url_for
Expand All @@ -175,51 +163,42 @@ def two():
res = client.get(url_for('one', _external=True))
assert res.status_code == 200
assert b'42' in res.data
"""
)
""")
result = appdir.runpytest("-v", "--no-start-live-server")
result.stdout.fnmatch_lines(["*passed*"])
assert result.ret == 0

@pytest.mark.parametrize("port", [5000, 5001])
def test_live_server_fixed_port(self, port, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

def test_port(live_server):
assert live_server.port == %d
"""
% port
)
""" % port)
result = appdir.runpytest("-v", "--live-server-port", str(port))
result.stdout.fnmatch_lines(["*PASSED*"])
assert result.ret == 0

@pytest.mark.parametrize("host", ["127.0.0.1", "0.0.0.0"])
def test_live_server_fixed_host(self, host, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

def test_port(live_server):
assert live_server.host == '%s'
"""
% host
)
""" % host)
result = appdir.runpytest("-v", "--live-server-host", str(host))
result.stdout.fnmatch_lines(["*PASSED*"])
assert result.ret == 0

def test_respect_wait_timeout(self, appdir):
appdir.create_test_module(
"""
appdir.create_test_module("""
import pytest

def test_should_fail(live_server):
assert live_server._process.is_alive()
"""
)
""")
result = appdir.runpytest("-v", "--live-server-wait=0.00000001")
result.stdout.fnmatch_lines(["**ERROR**"])
assert result.ret == 1
3 changes: 0 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ envlist =

[pytest]
norecursedirs = .git .tox env coverage docs
pep8ignore =
docs/conf.py ALL
pep8maxlinelength = 79

[testenv:dev]
commands =
Expand Down
Loading