import os
import sys

from invoke import task, run


CURRENT_DIR = os.path.dirname(__file__)
TESTS_DIR   = os.path.join(CURRENT_DIR, 'tests')


@task
def setup():
    """
    Prepares to run tests.
    """
    os.chdir(CURRENT_DIR)
    print("Current directory: {}".format(os.path.dirname(__file__)))


@task(pre=[setup])
def test_all():
    """
    Runs all test sets.
    """
    for dir in os.listdir(TESTS_DIR):
        if not os.path.isfile(os.path.join(TESTS_DIR, dir)) \
           and not dir.startswith('_') \
           and not dir.startswith('.'):
            test(dir)


@task(pre=[setup])
def test(name='fresh'):
    """
    Tests Mongo backup with fresh DB.
    """
    print("===== Testing '{}' set =====".format(name))
    run('{}/{}/run_test.py'.format(TESTS_DIR, name))
    print('')

@@ -224,24 +224,26 @@
 ENT_DIR)%0A   
+ #
  print(%22Curr
@@ -296,16 +296,16 @@
 le__)))%0A
-
 %0A%0A@task(
@@ -385,35 +385,27 @@
 for 
-dir in os.listdir(TESTS_DIR
+name in test_names(
 ):%0A 
@@ -415,30 +415,14 @@
     
-if not os.path.isfile(
+dir = 
 os.p
@@ -438,108 +438,20 @@
 TEST
-S
 _DIR, 
-dir)) %5C%0A           and not dir.startswith('_') %5C%0A           and not dir.startswith('.'):%0A    
+name)%0A
     
@@ -667,24 +667,24 @@
 DIR, name))%0A
-
     print(''
@@ -685,8 +685,405 @@
 int('')%0A
+%0A%0A@task(pre=%5Bsetup%5D)%0Adef list_test():%0A    %22%22%22%0A    Displays all test names.%0A    %22%22%22%0A    for name in test_names():%0A        print(name)%0A%0A%0Adef test_names():%0A    %22%22%22%0A    Retrieves all test names.%0A    %22%22%22%0A    return %5Bdir for dir in os.listdir(TESTS_DIR)%0A            if not os.path.isfile(os.path.join(TESTS_DIR, dir)) %5C%0A            and not dir.startswith('_') %5C%0A            and not dir.startswith('.')%5D%0A

make use of test_names()