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

Included contexts: wrong ordering and duplicates of before/after blocks #130

Closed m-kostrzewa closed 4 years ago

m-kostrzewa commented 5 years ago

I think there are two issues:

Example 1: just -each

from mamba import description, context, it, before, after, shared_context, included_context

with shared_context("A"):
    with before.each:
        print("A.BEFORE")
    with after.each:
        print("A.AFTER")

with shared_context("B"):
    with before.each:
        print("B.BEFORE")
    with after.each:
        print("B.AFTER")

with description("Example") as self:
    with included_context("A"):
        with included_context("B"):
            with it("IT"):
                print("IT")

Expected:

A.BEFORE
B.BEFORE
IT
B.AFTER
A.AFTER

Actual:

A.BEFORE
B.BEFORE
IT
A.AFTER
B.AFTER

Example 2: just -all

from mamba import description, context, it, before, after, shared_context, included_context

with shared_context("A"):
    with before.all:
        print("A.BEFORE")
    with after.all:
        print("A.AFTER")

with shared_context("B"):
    with before.all:
        print("B.BEFORE")
    with after.all:
        print("B.AFTER")

with description("Data extraction") as self:
    with included_context("A"):
        with included_context("B"):
            with it("IT"):
                print("IT")

Expected:

A.BEFORE
B.BEFORE
IT
B.AFTER
A.AFTER

Actual:

A.BEFORE
A.BEFORE
B.BEFORE
IT
A.AFTER
B.AFTER
A.AFTER

Example 3: -each and -all

from mamba import description, context, it, before, after, shared_context, included_context

with shared_context("A"):
    with before.each:
        print("A.BEFORE.EACH")
    with after.each:
        print("A.AFTER.EACH")
    with before.all:
        print("A.BEFORE.ALL")
    with after.all:
        print("A.AFTER.ALL")

with shared_context("B"):
    with before.each:
        print("B.BEFORE.EACH")
    with after.each:
        print("B.AFTER.EACH")
    with before.all:
        print("B.BEFORE.ALL")
    with after.all:
        print("B.AFTER.ALL")

with description("Data extraction") as self:
    with included_context("A"):
        with included_context("B"):
            with it("IT"):
                print("IT")

Expected:

A.BEFORE.ALL
B.BEFORE.ALL
A.BEFORE.EACH
B.BEFORE.EACH
IT
B.AFTER.EACH
A.AFTER.EACH
B.AFTER.ALL
A.AFTER.ALL

Actual:

A.BEFORE.ALL
A.BEFORE.ALL
B.BEFORE.ALL
A.BEFORE.EACH
B.BEFORE.EACH
IT
A.AFTER.EACH
B.AFTER.EACH
A.AFTER.ALL
B.AFTER.ALL
A.AFTER.ALL
m-kostrzewa commented 5 years ago

Actually, even for normal context, the ordering is wrong:

from mamba import description, context, it, before, after, shared_context, included_context

with description("Data extraction") as self:
    with context("A"):
        with before.each:
            print("A.BEFORE")
        with after.each:
            print("A.AFTER")
        with context("B"):
            with before.each:
                print("B.BEFORE")
            with after.each:
                print("B.AFTER")
            with it("IT"):
                print("IT")

Results are same as for included contexts in this case

m-kostrzewa commented 5 years ago

I'm using v0.10 from pip, but I saw some fixes on master branch, gonna try it

m-kostrzewa commented 5 years ago

^ My mistake, the fixes were from January, but a year ago... so no fix.