Git Product home page Git Product logo

Comments (3)

dacodekid avatar dacodekid commented on August 11, 2024

This could solve the problem currently I'm facing (or not sure I'm dealing it wrong). I'm trying to use this with pytest-django. My environment variables are in a separate file(s), and I'm loading them through from my manage.py file like below.

try:
    ENV = os.environ['ENV']
    with open('project/envs/env.' + ENV) as envfile:
        for line in envfile:
            if line.strip():
                setting = line.strip().split('=', maxsplit=1)
                os.environ.setdefault(setting[0], setting[1])

except KeyError:
    print('ENV Key Not Provided')

except FileNotFoundError as e:
    print('ENV File Doesn\'t Exist')

So ENV=test(/dev) python manage.py ..... will load my required ENV file before it loads settings.py.

By following pytest-django 's documentation, I've created a Test Runner class and TEST_RUNNER in my settings.py. This also works fine as expected by running the same command above ENV=test python manage.py test.

Trying to introduce pytest-watch here doesn't do the trick for me. It always trying to load the settings.py file and fails as there are no ENV variables. I also tried to move the above code inside my custom_test_runner.py file and run with --runner "python custom_test_runner.py" but it still trying to load the settings.py even before it executes the custom_test_runner.

from pytest-watch.

blueyed avatar blueyed commented on August 11, 2024

@dacodekid
Just curious: why do you use TEST_RUNNER. It is easier to run just pytest by itself.
Check out https://github.com/jezdez/envdir/ for env(dir) handling.

from pytest-watch.

dacodekid avatar dacodekid commented on August 11, 2024

@blueyed I was aware of that package as my settings.py is based on this article which suggests envdir (original one). But I was skeptical about having one file per setting. For now I choose xdist as my alternate. Still think pytest-watch as a plugin would make more sense than its current form.

from pytest-watch.

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.