
from steps.bdd_test_util import cli_call

def after_scenario(context, scenario):
	if 'doNotDecompose' in scenario.tags:
		print("Not going to decompose after scenario {0}, with yaml '{1}'".format(scenario.name, context.compose_yaml))
	else:
		if 'compose_yaml' in context:
			print("Decomposing with yaml '{0}' after scenario {1}, ".format(context.compose_yaml, scenario.name))
			context.compose_output, context.compose_error, context.compose_returncode = \
        		cli_call(context, ["docker-compose", "-f", context.compose_yaml, "kill"], expect_success=True)
			context.compose_output, context.compose_error, context.compose_returncode = \
        		cli_call(context, ["docker-compose", "-f", context.compose_yaml, "rm","-f"], expect_success=True)
            # now remove any other containers (chaincodes)
			context.compose_output, context.compose_error, context.compose_returncode = \
        		cli_call(context, ["docker",  "ps",  "-qa"], expect_success=True)
        	if context.compose_returncode == 0:
        		# Remove each container
        		for containerId in context.compose_output.splitlines():
        			#print("docker rm {0}".format(containerId))
        			context.compose_output, context.compose_error, context.compose_returncode = \
                        cli_call(context, ["docker",  "rm", containerId], expect_success=True)




@@ -75,16 +75,306 @@
 nario):%0A
+    if context.failed:%0A        filename = scenario.name.replace(%22 %22, %22_%22)%0A        for containerData in context.compose_containers:%0A            logfile = containerData.containerName + filename%0A            print(%22********** Test failed. Docker container logs written to %7B0%7D%22.format(logfile))%0A
 %09if 'doN
@@ -1637,11 +1637,8 @@
 s=True)%0A
-%0A%0A%0A

add context.failed check to after_scenario() call