def tearDown(self):

        # Delete the deployed directory.
        try:
            pass
            #shutil.rmtree("weblabtest")
        except:
            pass

        # Remove running weblab instances.
        os.system("kill $(ps aux | grep 'python -OO.*wcloud' | awk '{print $2}')")

        # Remove the testentity line if present. Otherwise, the next attempt to start-weblab will fail
        # because its folder will be removed.
        try:
            instances_file = os.path.join(flask_app.config["DIR_BASE"], "instances.txt")
            f = file(instances_file)
            lines = f.readlines()
            lines = [line.replace("\n", "") + "\n" for line in lines if not "testentity" in line]
            f.close()
            f = file(instances_file, "w")
            f.writelines(lines)
            f.close()
        except:
            pass

        # Remove the include from apache.conf
        apacheconf = os.path.join(flask_app.config["DIR_BASE"], "apache.conf")
        lines = open(apacheconf, "r").readlines()
        cleared_lines = [line.strip() + "\n" for line in lines if "testentity" not in line]
        open(apacheconf, "w").writelines(cleared_lines)

        # Make sure all the instances are stopped. DANGEROUS: This will kill all running instances of WebLab.
        # This is done, specifically, so that "testentity" instance is killed after being run, so that
        # the test can be run again without issues.l
        try:
            os.system("killall weblab-admin")
        except:
            pass

        # TODO: Careful with this. It is dangerous, in production if configured wrongly it would
        # erase the whole deployments directory.
        try:
            base_url = os.path.join(flask_app.config["DIR_BASE"], self._settings[Creation.BASE_URL])
            shutil.rmtree(base_url)
        except:
            pass

        # Give it some time. It seems to be necessary.
        time.sleep(1.5)
dataset/ETHPy150Open weblabdeusto/weblabdeusto/tools/wcloud/wcloud/test/test_wcloud_tasks.py/TestWcloudTasks.tearDown/original