Giter Site home page Giter Site logo

Comments (10)

bittner avatar bittner commented on August 26, 2024

Thanks for reporting this problem in such a great detail!

This might be related to what @sebastianmanger explains in #66 (comment). Could you take a look?

I'm not sure if this feature ever worked, hmmm. We need to get it working now.

from behave-django.

jenisys avatar jenisys commented on August 26, 2024

@Exanis
The behave step decorator @given(...) registers the function object in the step registry.
Therefore, I assume that you need to change the order of the decorators to fix the problem, like:

@given('a default project database exist')
@fixtures("test_project.json")
def project_database(context):
    pass

Have you tried this ?

from behave-django.

bittner avatar bittner commented on August 26, 2024

@jenisys Unfortunately, swapping the decorator order doesn't change anything about the failing tests. At least in the behave_django code base.

from behave-django.

Exanis avatar Exanis commented on August 26, 2024

@bittner I agree, it seems to be the same problem :)

If that may help to fix / help people with the same problem that I have, I did this workaround:

  • Create a step like this:
@given("i load fixture (?P<fixture>.+)")
def load_fixture(context, fixture):
    pass

As you can see, this step basically do nothing but allow me to get a fixture and have a common sentence for this. Then I added to my environment.py

def django_ready(context):
    for step in context.scenario.all_steps:
        match = re.match(r"i load fixture (?P<fixture>.+)", step.name)
        if match:
            if not context.test.fixtures:
                context.test.fixtures = []
            context.test.fixtures.append(match.group('fixture'))
    context.test._fixture_setup()

The feeling is not really "behavish" as it is, because I end up with steps like:
"Given i load fixture test_project.json"

I didn't change much more than that since I'm using it for an API, so everybody who do write those tests do know what a json is ; but it could be better to change it a bit to avoid adding the ".json", that would make it more "readable" from a non-tech point of view.

from behave-django.

sebastianmanger avatar sebastianmanger commented on August 26, 2024

This happens because of the issue discussed in #66
I didn't reply, as I am having a fever these days. I can probably look into it next week.
@Exanis maybe this will help for the moment: https://behave.readthedocs.io/en/latest/fixtures.html

from behave-django.

bittner avatar bittner commented on August 26, 2024

@sebastianmanger Do you have time to look into fixing this issue this weekend?

from behave-django.

sebastianmanger avatar sebastianmanger commented on August 26, 2024

I did some digging, here's my findings:

  • The registry of steps (provided by behave) is populated after the call to 'setup_fixtures', fixture loading depends on the registry.
  • I am not familiar with the internals of behave / registering the steps. But one approach may be to load steps from within behave-django.
  • Another approach may be to use djangos module loading helper to import all decorators from the steps.

As I am more familiar with django than with behave, I would tend to implement the latter. I can look into it, just expect some lag... If someone else can do it, all the better!

from behave-django.

bittner avatar bittner commented on August 26, 2024

@sebastianmanger, please go ahead with the route that is easiest for you. It's of great help! 👍

@jenisys any suggestions or concerns?

from behave-django.

jenisys avatar jenisys commented on August 26, 2024

@sebastianmanger @bittner
Pull-request #72 should fix the problem (IMHO).

from behave-django.

bittner avatar bittner commented on August 26, 2024

Fixed with #72 via 8bff23e.

from behave-django.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.