Skip to content

Commit

Permalink
code refactor to fix duplication in pytest fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsadman committed Nov 29, 2019
1 parent ce747d2 commit 6fee977
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Config:

# general config
SECRET_KEY = os.environ.get("FLASK_SECRET_KEY")
PROPAGATE_EXCEPTIONS = True

# database
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from config import Config as config_prod
from config_dev import Config as config_dev
from application import create_app


def wrapper_client(branch):
if branch == "dev":
app_config = config_dev
else:
app_config = config_prod

flask_app = create_app(app_config)
testing_client = flask_app.test_client()
return testing_client
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions tests/test_dev/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest
from dotenv import load_dotenv
from application import create_app
from config_dev import Config
from tests.conftest_wrapper import wrapper_client

# holds all the fixtures
# fixtures are ran once during request, this client will be passed in
Expand All @@ -10,6 +8,4 @@

@pytest.fixture(scope="module")
def client(request):
flask_app = create_app(Config)
testing_client = flask_app.test_client()
return testing_client
return wrapper_client("dev")
8 changes: 2 additions & 6 deletions tests/test_prod/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest
from dotenv import load_dotenv
from application import create_app
from config import Config
from tests.conftest_wrapper import wrapper_client

# holds all the fixtures
# fixtures are ran once during request, this client will be passed in
Expand All @@ -10,6 +8,4 @@

@pytest.fixture(scope="module")
def client(request):
flask_app = create_app(Config)
testing_client = flask_app.test_client()
return testing_client
return wrapper_client("prod")

0 comments on commit 6fee977

Please sign in to comment.