Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
How should I unit test MySQL queries?

I'm building some unit tests for my Python module which interfaces with a MySQL database via SQLAlchemy. From reading around I gather the best way to do this is to create a test database that I can query as if it was the real thing. I've done this however how should I test the existing queries in the module as they currently all point at the live database?

The only idea I'd come up with was to do something like the following:

def run_query(engine, db_name='live_db')
    engine.execute(f'SELECT * FROM {db_name}.<table_name>')

I could then pass in test_db when I run the function from unittest. Is there a better way?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For a scalable testing approach, I would suggest having an intermediate DAL Layer than should decide to which DB the query should be routed.

Testing with a Test Database

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!