Skip to content

Codespace didactic space fishstick rwgwpqp499x3qj9 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To run the Flask application, follow these steps:
>**Note** - In Windows, the `venv` does not have a `bin` directory. Therefore, you'd use the analogous command shown below:

```bash
source venv\Scripts\activate
source .venv\Scripts\activate
```

1. **Install the app as an editable package:**
Expand All @@ -44,12 +44,26 @@ To run the Flask application, follow these steps:
python3 -m flask --app src.flaskapp run --reload
```

### Run the tests
### Development

1. **Inside your virtual environment, execute the following command to run the tests**
1. **Inside your virtual environment, execute the following command to install the development requirements:**

```bash
python flask_test.py
pip install -r requirements-dev.txt
```

1. **Execute the following command to install the pre commit hooks:**

```bash
pre-commit install
```

### Testing

1. **Execute the following command to run the tests**

```bash
pytest
```

## API Documentation
Expand Down Expand Up @@ -212,5 +226,3 @@ The API will return these error types when the request fails:
"total_executions": 10
}
```


157 changes: 0 additions & 157 deletions flask_test.py

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extend-exclude = "src/flaskapp/migrations/"

[tool.pytest.ini_options]
addopts = "-ra --cov"
testpaths = ["tests"]
pythonpath = ["src"]

[tool.coverage.report]
Expand Down
38 changes: 38 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

import pytest

from flaskapp import create_app
from flaskapp.database.models import db


@pytest.fixture(scope="session")
def app_with_db():
"""Session-wide test `Flask` application."""
config_override = {
"TESTING": True,
# Allows for override of database to separate test from dev environments
"SQLALCHEMY_DATABASE_URI": os.environ.get("TEST_DATABASE_URL", os.environ.get("DATABASE_FILENAME")),
}
app = create_app(config_override)

with app.app_context():
engines = db.engines

engine_cleanup = []

for key, engine in engines.items():
connection = engine.connect()
transaction = connection.begin()
engines[key] = connection
engine_cleanup.append((key, engine, connection, transaction))

yield app

for key, engine, connection, transaction in engine_cleanup:
try:
transaction.rollback()
connection.close()
except Exception:
connection.close()
engines[key] = engine
Loading
Loading