0

I am writing a Python test class with methods relying on a connection to a MySQL database. The purpose of the test class is to test another class used for simplifying interaction with the same database. The interaction is managed through pymysql which requires login credentials to a MySQL account.

I am investigating the possibility of automatically creating a MySQL test user on any server when executing the tests. My goal is to be able to install the code as a package and have the tests run with a setup procedure that returns the connection to a database without any involvement from the user.

I am currently only familiar with creating MySQL users through an already existing superuser. The temporary solution is to include a file with login credentials that is read and used by the test module.

I might be that I approach the problem from a completely wrong angle. In general I am trying to test code that executes MySQL commands and commits changes to a database. I am grateful of any tips, ideas or experiences.

Cheers,

GSEL
  • 51
  • 1
  • 2
  • 8

1 Answers1

0

Ideally your tests should not touch your DB at all. If you are testing your code - then tests should execute your code and check the correctness of the result. If DB is included in your testing process, then you are testing your code + DB.

For testing you should mock the PyMysql module itself, I agree with this answer

Andrew Morozko
  • 2,576
  • 16
  • 16