From the course: Managing Python Projects

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Fixtures

Fixtures - Python Tutorial

From the course: Managing Python Projects

Start my 1-month free trial

Fixtures

- [Instructor] Test fixtures creates a null environment for testing. A server tests need a database with some data in it. You can use a fixture to create such as database and populate it before every test run or every test file run. As soon as you have a code to create a table in a database. We have db.py. We have the definition of the sql_schema. And in line 15, create_schema which will populate the database with the new schema, creating tables there. To have the database automatically created you can use a pytest fixture. You should use a file length conftest in the test directory. We input pytest and we input sqlite3 which is an impeded database that comes with the Python. In line six, we define a function called database. And in line five we decorate it with pytest.fixture. In line seven we create the connection. In line eight we yield the connection. Pytest will lose this connection. And once the test is…

Contents