How to run specific code after all tests are executed?

You can use a autouse fixture with session scope: @pytest.fixture(scope=”session”, autouse=True) def db_conn(): # Will be executed before the first test conn = db.connect() yield conn # Will be executed after the last test conn.disconnect() You can then also use db_conn as an argument to a test function: def test_foo(db_conn): results = db_conn.execute(…)

How to pass environment variables to pytest

Another alternative is to use the pytest-env plugin. It can be configured like so: [pytest] env = HOME=~/tmp D:RUN_ENV=test the D: prefix allows setting a default value, and not override existing variables passed to py.test. Note: you can explicitly run pytest with a custom config, if you only sometimes need to run a specialized environment … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)