Statement before import not working, database keeps getting erased everytime I run tests

68 Views Asked by At

I'm following the flask mega tutorial by M Grinberg, which at a point runs some tests for new functionalities. Every time I run tests.py the database is erased (luckly it's easy te re create) This is the supposed problematic part of the code in the test.py file:

import os 
os.environ['DATABASE_URL'] = 'sqlite://' 

from datetime import datetime, timezone, timedelta
import unittest
from app import app, db
from app.models import User, Post

the os.environ['DATABASE_URL'] = 'sqlite://' statement is meant to override the database and change the application configuration to direct SQLAlchemy to use an in-memory SQLite database during the tests, so the test doesn't mess up the actual database.

It seems someone else already found the same problem and their solution was to change from autopep8 to Black Formatter, it also pointed me to Allow statements before imports with Visual Studio Code and autopep8 where the solution was to mark the statement before the imports with #noqa, or to add the comment "autopep8.args": ["--ignore", "E402"] to the autopep args in the settings. None of this has worked for me so far, so I figure I ask the question again.

EDIT: I applied format with both autopep8 and black formatter, no changes though, I'm starting to think maybe the problems is somewhere else? Thanks for the help! with autopep8

with black-formatter

0

There are 0 best solutions below