pytest with inmemory mysql setup for tests - can't get fixtures to work

Viewed 86

new to pytest.

I am trying to create a test class with several tests in it. Now, I want this test to:

  1. create in memory mysql and schema with tables (only once)
  2. truncate tables (after each test)
  3. dispose in memory mysql

After some research I came across pytest-mysql but I just cannot make it work with the fixtures.

I tried some different test settings:

  • In the following case The mysql param is a bound method returning None if invoke it.

      from pytest_mysql import factories
    
      mysql_process = factories.mysql_proc(port=8888, logs_prefix='/tmp')         
      mysql = factories.mysql('mysql_my_proc')
    
    
    
     class BaseTest(object):
    
        @pytest.mark.usefixtures('mysql')
        def setup_method(self, mysql):
            self._setup_mysql(mysql)
    
  • In this case I didn't get anythin in the mysql param at all.

       from pytest_mysql import factories
    
       mysql_process = factories.mysql_proc(port=8888, logs_prefix='/tmp')         
       mysql = factories.mysql('mysql_my_proc')
    
    
    
      class BaseTest(object):
    
         def setup_method(self, mysql):
             self._setup_mysql(mysql)
    
  • In this case I had errors of scoping (found it here on stack overflow):

       from pytest_mysql import factories
    
       mysql_process = factories.mysql_proc(port=8888, logs_prefix='/tmp')         
       mysql = factories.mysql('mysql_my_proc')
    
    
      class BaseTest(object):
    
         @classmethod
         @pytest.fixture(scope="class", autouse=True)
         def setup(self):
             self._setup_mysql(mysql)
    

I haven't even started to think about truncate and teardown phases.. yet.

Can anybodey help me here?

0 Answers
Related