# Buggy code
def TestInit():
    """Only used in tests and will rerun all the hooks to create a clean state."""
    # Tests use both the server template grr_server.yaml as a primary config file
    # (this file does not contain all required options, e.g. private keys), and
    # additional configuration in test_data/grr_test.yaml which contains typical
    # values for a complete installation.
    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    flags.FLAGS.config = config_lib.Resource().Filter(
        "install_data/etc/grr-server.yaml"
    )

    flags.FLAGS.secondary_configs = [
        config_lib.Resource().Filter("test_data/grr_test.yaml")
    ]

    # We are running a test so let the config system know that.
    config_lib.CONFIG.AddContext("Test Context", "Context applied when we run tests.")

    AddConfigContext()
    ConfigInit()

    # Tests additionally add a test configuration file.
    ServerLoggingStartupInit()
    registry.TestInit()


# Traceback (IOError)
Traceback (most recent call last):
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/gui/http_api.py", line 415, in HandleRequest
rendered_data = self.CallApiHandler(handler, args, token=token)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/gui/http_api.py", line 225, in CallApiHandler
return handler.Render(args, token=token)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/gui/api_plugins/config.py", line 80, in Render
parameter_data = RenderConfigOption(parameter)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/gui/api_plugins/config.py", line 25, in RenderConfigOption
option_value = config_lib.CONFIG.Get(name)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 1162, in Get
type_info_obj=type_info_obj, context=calc_context)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 1291, in InterpolateValue
parameter=type_info_obj.name, context=context).Parse()
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 671, in Parse
self.Close()
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/lexer.py", line 187, in Close
while self.NextToken():
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/lexer.py", line 127, in NextToken
possible_next_state = cb(string=m.group(0), match=m)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 657, in ExpandArg
final_value = self.config.Get(parameter_name, context=self.context)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 1162, in Get
type_info_obj=type_info_obj, context=calc_context)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 1291, in InterpolateValue
parameter=type_info_obj.name, context=context).Parse()
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 671, in Parse
self.Close()
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/lexer.py", line 187, in Close
while self.NextToken():
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/lexer.py", line 127, in NextToken
possible_next_state = cb(string=m.group(0), match=m)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 640, in Filter
arg = filter_object().Filter(arg)
File "/home/dev/GRR_ENV/local/lib/python2.7/site-packages/grr/lib/config_lib.py", line 220, in Filter
raise IOError("Unable to find resource %s" % filename)
IOError: Unable to find resource test_data

# Fixed code
def TestInit():
    """Only used in tests and will rerun all the hooks to create a clean state."""
    # Tests use both the server template grr_server.yaml as a primary config file
    # (this file does not contain all required options, e.g. private keys), and
    # additional configuration in test_data/grr_test.yaml which contains typical
    # values for a complete installation.
    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    flags.FLAGS.config = config_lib.Resource().Filter(
        "install_data/etc/grr-server.yaml"
    )

    flags.FLAGS.secondary_configs = [
        config_lib.Resource().Filter("test_data/grr_test.yaml@grr-response-test")
    ]

    # We are running a test so let the config system know that.
    config_lib.CONFIG.AddContext("Test Context", "Context applied when we run tests.")

    AddConfigContext()
    ConfigInit()

    # Tests additionally add a test configuration file.
    ServerLoggingStartupInit()
    registry.TestInit()