To receive notifications about scheduled maintenance, please subscribe to the mailing-list You can subscribe to the mailing-list at

Commit d6327780 authored by vermeul's avatar vermeul
Browse files

added fixtures

parent 7a73db68
......@@ -15,3 +15,45 @@ $ pytest tests/
$ pytest tests/ -k "MyClass and not weird_test"
$ pytest tests/ -k "test_current_work"
## Fixtures
* create a file named `` within the `tests` folder
* add one or many fixtures as shown below
* set the `scope` to either `function`, `class`, `module`, `package` or `session` (see
* typically, database connections or other slow operations are `scope=session` to save time
import pytest
import os
def mysql_conn():
db_host = os.getenv("DB_HOST")
db_name = os.getenv("DB_NAME")
db_user = os.getenv("DB_USER")
db_password = os.getenv("DB_PASSWORD")
engine = create_engine(
connection = engine.connect()
yield connection
And then use fixture in your testing module(s), using the `mysql_conn` fixture as the first parameter:
import pytest
def test_select_something(mysql_conn):
mycursor = mysql_conn.cursor()
mycursor.execute("SELECT * FROM customers")
myresult = mycursor.fetchall()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment