import os
import random
from shutil import copyfile

from behaving import environment as benv
from behaving.web.steps import *
from behaving.personas.steps import *

from test_config import CREDENTIALS, MISTCREDS, TESTNAMES

PERSONAS = {
    'NinjaTester': dict(
        creds=CREDENTIALS,
        mistcreds=MISTCREDS,
        machine=TESTNAMES['machine_name']+str(random.randint(1, 10000)),
        image_machine=TESTNAMES['image_machine']+str(random.randint(1, 10000)),
        key_name=TESTNAMES['key']+str(random.randint(1, 10000))
    )
}


def before_all(context):
    benv.before_all(context)
    context.personas = PERSONAS
    try:
        copyfile("db.yaml", "db.yaml.test_backup")
        os.remove("db.yaml")
        print "Removing file"
    except:
        pass


def after_all(context):
    try:
        copyfile("db.yaml.test_backup", "db.yaml")
        os.remove("db.yaml.test_backup")
    except:
        pass


def before_feature(context, feature):
    benv.before_feature(context, feature)


def before_scenario(context, scenario):
    benv.before_scenario(context, scenario)
    context.personas = PERSONAS


def after_scenario(context, scenario):
    benv.after_scenario(context, scenario)
@@ -159,16 +159,25 @@
 port *%0A%0A
+try:%0A    
 from tes
@@ -227,16 +227,20 @@
 TNAMES%0A%0A
+    
 PERSONAS
@@ -248,16 +248,20 @@
 = %7B%0A    
+   
+ 
 'NinjaTe
@@ -281,16 +281,20 @@
         
+    
 creds=CR
@@ -312,16 +312,20 @@
         
+   
+ 
 mistcred
@@ -337,16 +337,20 @@
 TCREDS,%0A
+    
         
@@ -422,16 +422,20 @@
         
+  
+  
 image_ma
@@ -506,16 +506,20 @@
         
+    
 key_name
@@ -574,12 +574,36 @@
     
-)%0A%7D%0A
+    )%0A    %7D%0Aexcept:%0A    pass
 %0A%0Ade

Fix auto importing test_config if it is not there