nestorsalceda / mamba

The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD).
http://nestorsalceda.github.io/mamba
MIT License
520 stars 64 forks source link

before.all/after.all should only run once when using nested hooks #105

Open razorx89 opened 6 years ago

razorx89 commented 6 years ago

When using nested hooks, mamba executes the whole stack of hooks instead of only the hooks in the current scope. See the MWE for more details. This problem is also present with the after.all hook.

spec.py:

from mamba import before, description, it
from expects import *

num_outer_called = 0
num_inner_called = 0

with description('Bug'):
    with before.all:
        global num_outer_called
        num_outer_called += 1
        print('outer.before.all')

    with it('should have run before.all once'):
        expect(num_outer_called).to(equal(1))

    with description('when having a nested before.all'):
        with before.all:
            global num_inner_called
            num_inner_called += 1
            print('inner.before.all')

        with it('should have run the inner before.all once'):
            expect(num_inner_called).to(equal(1))

        with it('should have still run the outer before.all only once'):
            expect(num_outer_called).to(equal(1))  # Failed with 'expected: 2 to equal 1'
nestorsalceda commented 6 years ago

Hey @razorx89

Is this happening with latest release?

I think this was fixed in 65100b5d1d1d3d3f87c0f781afcfbaebe194563f and d4d074465d6092d152a33679aae8c10e734b4a4c but perhaps I missed some detail.

Thanks!

ksaifullah commented 5 years ago

Experiencing this problem. . .