0

I ran into a problem when using python-behave.

I create a sandbox database before every scenario and destroy it after scenario.

But memory usage increase about 20MB for every scenario, and total usage is about 3.xGB for all test case(LoL).

My question is why memory is not released when i call context.runner.teardown_databases()?

        from django.test.runner import DiscoverRunner
        def before_scenario(context, scenario):
            context.runner = DiscoverRunner()
            context.runner.setup_test_environment()
            context.old_db_config = context.runner.setup_databases()

        def after_scenario(context, scenario):
            context.runner.teardown_databases(context.old_db_config)
            context.runner.teardown_test_environment()

    Feature:
      Scenario: 
        Given I have a debit card
        When I withdraw 200 
        Then I should get $200 in cash
    @given('I have a debit card')
    def step1(context):
        pass
    @given('I withdraw 200')
    def step2(context):
        pass
    @given('I should get $200 in cash')
    def step3(context):
        pass

python-behave:version 1.2.5

django:version 1.8.0

python:version 2.7

Any suggestion is appreciated.

nelson
  • 1
  • 3

1 Answers1

0

After adding gc.garbage(), i found root cause.

def after_scenario(context, scenario):
    context.runner.teardown_databases(context.old_db_config)
    context.runner.teardown_test_environment()
    gc.collect()
    print gc.garbage

Those objects which are uncollecable should be model instance, because of those instances are cyclic referenced. Then i add a purge function for deleting thmem, the memory is normal now.

nelson
  • 1
  • 3