Skip to content
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

Fixes erratic tests #301

Merged
merged 7 commits into from
Aug 15, 2024
Merged

Fixes erratic tests #301

merged 7 commits into from
Aug 15, 2024

Conversation

bdc34
Copy link
Contributor

@bdc34 bdc34 commented Aug 15, 2024

The tests that used the DB were failing in about 1 out of 7 runs due to the flask context being different than the context the database got created in.

I fixed this by moving to pytests and away from UnitTests and with a change to legacy.util.create_all()

Breaking changes:

  1. arxiv.db.session is now at arxiv.db.Session to be more like the SQLAlchemy docs
  2. arxiv.db.models.configure_db has moved to arxiv.db

Non flask code can use the db like this:

# env var set in cloud run etc 
# CLASSIC_DB_URI = 'mysql://bla/bla/bla"
from arxiv.db import Session
from arxiv.db.models import Metadata
rows = Session.query(Metadata).fetchall()

Flask code can do this:

# CLASSIC_DB_URI = 'mysql://bla/bla/bla"
from arxiv.db import Session
from arxiv.db.models import Metadata

app = Flask('xyz')

@app.route('/metadata')
def md():
    rows = Session.query(Metadata).fetchall()

Code that needs special configs can do:

from arxiv.config import Settings
from arxiv import db
from arxiv.db.models import Metadata

db.init(Settings(CLASSIC_DB_URI="sqlite:////tmp/somefile.db")
rows = db.Session.query(Metadata).fetchall()

Removes setting of os.environ to sqlite memory
This obscured the original db error.
The tests were failing about 1 out of 7 times. This seemed to be
due the tables being created in a DB and then the tests using a different DB.
The tests where this was happening were rewritten using pytest instead of UnitTest.
Breaking change.

Done to be more similar to the sqlalchemy docs.

Removes little used get_db and get_engine.
Breaking change:
arxiv.db.models.configure_db moved to arxiv.db.configure_db
@bdc34 bdc34 requested a review from a team August 15, 2024 17:19
@bdc34 bdc34 merged commit 1e819b1 into develop Aug 15, 2024
1 check passed
@jonathanhyoung jonathanhyoung deleted the bdc34/fix-erratic-tests branch August 22, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants