Skip to content

Commit 474517f

Browse files
author
Fabien Coelho
committed
remove deprecated _URL stuff
1 parent 9974a61 commit 474517f

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

FlaskTester.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -535,28 +535,30 @@ def _ft_client(authenticator):
535535
default_login = os.environ.get("FLASK_TESTER_DEFAULT", None)
536536
client: Client
537537

538-
app_def = os.environ.get("FLASK_TESTER_URL", "app")
539-
app_def = os.environ.get("FLASK_TESTER_APP", app_def)
538+
test_app = os.environ.get("FLASK_TESTER_APP", "app")
540539

541-
if app_def.startswith("http://") or app_def.startswith("https://"):
542-
client = RequestClient(authenticator, app_def, default_login)
540+
if test_app.startswith("http://") or test_app.startswith("https://"):
541+
client = RequestClient(authenticator, test_app, default_login)
543542
else:
544543
# load app package
545-
pkg_name, app = app_def, None
546-
app_names = ["app", "application", "create_app", "make_app"]
547-
if ":" in pkg_name: # override defaults
548-
pkg_name, app_name = pkg_name.split(":", 1)
544+
if ":" in test_app: # override defaults
545+
pkg_name, app_name = test_app.split(":", 1)
549546
app_names = [app_name]
547+
else:
548+
pkg_name = test_app
549+
app_names = ["app", "application", "create_app", "make_app"]
550550
pkg = importlib.import_module(pkg_name)
551551
# find app in package
552+
app = None
552553
for name in app_names:
553554
if hasattr(pkg, name):
554555
app = getattr(pkg, name)
555556
if callable(app) and not hasattr(app, "test_client"):
556557
app = app()
557558
break
559+
# none found
558560
if not app:
559-
raise FlaskTesterError(f"cannot find Flask app in {pkg_name}")
561+
raise FlaskTesterError(f"cannot find Flask app in {pkg_name} ({test_app})")
560562
client = FlaskClient(authenticator, app.test_client(), default_login)
561563

562564
return client

docs/versions.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
55
see also the [documentation](https://zx80.github.io/flask-tester/),
66
please report any [issues](https://github.com/zx80/flask-tester/issues).
77

8-
## TODO
9-
10-
- remove deprecated features on 4.0
11-
12-
## ? on ?
8+
## 4.0 on ?
139

1410
Improved documentation and tests.
11+
Remove deprecated `FLASK_TESTER_URL`, simplifying code in passing.
1512

1613
## 3.6 on 2024-03-30
1714

tests/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SEED := $(shell head -c 33 /dev/urandom | base64)
2121
check.external:
2222
source $(VENV)/bin/activate
2323
export TEST_SEED="$(SEED)"
24-
export FLASK_TESTER_URL="http://localhost:$(PORT)"
24+
export FLASK_TESTER_APP="http://localhost:$(PORT)"
2525
# app
2626
flask --app app run --port=$(PORT) &
2727
flask_pid=$$!

tests/test_app.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
def test_sanity():
2424
# must provide url or package of Flask application to test
25-
assert "FLASK_TESTER_URL" in os.environ or "FLASK_TESTER_APP" in os.environ
25+
assert "FLASK_TESTER_APP" in os.environ
2626
# log.debug(f"TEST_SEED={os.environ.get('TEST_SEED')}")
2727

2828
# example from README.md
@@ -309,21 +309,17 @@ def test_client_fixture():
309309
# ft_client coverage
310310
auth = ft._ft_authenticator()
311311
# check and save env
312-
url = None
313-
if "FLASK_TESTER_URL" in os.environ: # pragma: no cover
314-
url = os.environ["FLASK_TESTER_URL"]
315-
del os.environ["FLASK_TESTER_URL"]
316312
app = None
317313
if "FLASK_TESTER_APP" in os.environ:
318314
app = os.environ["FLASK_TESTER_APP"]
319315
del os.environ["FLASK_TESTER_APP"]
320316
# no url nor app, defaults to "app"
321317
init = ft._ft_client(auth)
322318
# url
323-
os.environ["FLASK_TESTER_URL"] = "http://localhost:5000"
319+
os.environ["FLASK_TESTER_APP"] = "http://localhost:5000"
324320
init = ft._ft_client(auth)
325321
assert isinstance(init, ft.RequestClient)
326-
del os.environ["FLASK_TESTER_URL"]
322+
del os.environ["FLASK_TESTER_APP"]
327323
# bad package
328324
os.environ["FLASK_TESTER_APP"] = "no_such_package"
329325
try:
@@ -340,7 +336,5 @@ def test_client_fixture():
340336
assert True, "expected error raised"
341337
del os.environ["FLASK_TESTER_APP"]
342338
# reset env
343-
if url: # pragma: no cover
344-
os.environ["FLASK_TESTER_URL"] = url
345339
if app:
346340
os.environ["FLASK_TESTER_APP"] = app

0 commit comments

Comments
 (0)