From c8607ae8bb5c0eb4d16cf8b5f28cf453ddb579ff Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Tue, 16 Feb 2021 21:42:26 +0100 Subject: [PATCH] Use session/client fixture --- backend/tests/conftest.py | 12 ++++-------- backend/tests/test_backend.py | 10 +++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index cf7165d3..b61cc133 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -13,7 +13,6 @@ import os # https://www.python-boilerplate.com/py3+flask+pytest/ - @pytest.fixture(scope='session') def app(request): """Create application for the tests.""" @@ -23,7 +22,6 @@ def app(request): datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path']) _app = changedetection_app(app_config, datastore) - # Establish an application context before running the tests. ctx = _app.app_context() ctx.push() @@ -34,13 +32,11 @@ def app(request): request.addfinalizer(teardown) return _app +@pytest.fixture(scope='session') +def client(app): + return app.test_client() + @pytest.fixture(scope='function') def session(request): """Creates a new database session for a test.""" - - - def teardown(): - print ("teardown") - - request.addfinalizer(teardown) return session diff --git a/backend/tests/test_backend.py b/backend/tests/test_backend.py index b27c1743..55dab50c 100644 --- a/backend/tests/test_backend.py +++ b/backend/tests/test_backend.py @@ -12,13 +12,13 @@ import requests # https://www.python-boilerplate.com/py3+flask+pytest/ -def test_import(session): - res = session.get("/") +def test_import(client): + res = client.get("/") assert b"IMPORT" in res.data assert res.status_code == 200 test_url_list = ["https://slashdot.org"] - res = session.post('/import', data={'urls': "\n".join(test_url_list)}, follow_redirects=True) + res = client.post('/import', data={'urls': "\n".join(test_url_list)}, follow_redirects=True) s = "{} Imported".format(len(test_url_list)) #p= url_for('test_endpoint', _external=True @@ -33,7 +33,7 @@ def test_import(session): #assert response.json() == [{'id': 1}] -def test_import_a(session): - res = session.get("/") +def test_import_a(client): + res = client.get("/") assert b"IMPORT" in res.data assert res.status_code == 200