Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Django hooks are uncalled #331

Open
vshjxyz opened this Issue · 0 comments

1 participant

@vshjxyz

Hello,

It seems that the Django hooks (before.each_app in particular) remains uncalled.

I've debugged lettuce and found that in harvest.py:

registry.call_hook('before', 'harvest', locals())
results = []
try:
    for path in paths:
        app_module = None
        if isinstance(path, tuple) and len(path) is 2:
            path, app_module = path

    if app_module is not None:
        # THIS HOOK IS CALLED BEFORE INCLUDING ANY TEST FILE, SO THE FIRST TIME IT'S ALWAYS UNCALLED
        registry.call_hook('before_each', 'app', app_module)

    runner = Runner(path, options.get('scenarios'), verbosity,
                    enable_xunit=options.get('enable_xunit'),
                    xunit_filename=options.get('xunit_file'),
                    tags=tags, failfast=failfast, auto_pdb=auto_pdb)

    result = runner.run() # INSIDE THE run() ALL THE TEST FILES ARE INCLUDED
    if app_module is not None:
        registry.call_hook('after_each', 'app', app_module, result)

So basically the hook is always called before including the decorated methods for the first time.
I'll see if I have some time to propose a pull request but I think that this is something pretty urgent :\

The needing of a before.each_app hook for me is essential because I have different kind of browsers instantiated for different apps, and no apps reference in the before.each_scenario or before.each_feature

This small hack can resolve the problem:

    for path in paths:
        app_module = None
        if isinstance(path, tuple) and len(path) is 2:
            path, app_module = path

    if app_module is not None:
        from lettuce.terrain import before
        @before.all # THIS HOOK IS CALLED THE FIRST TIME IN THE run() METHOD
        def call_before_each():
            registry.call_hook('before_each', 'app', app_module)
        call_before_each()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.