Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running pytest programatically, like pytest - how should I be doing this? #92

Open
mrchrisadams opened this issue Jul 18, 2018 · 0 comments

Comments

@mrchrisadams
Copy link

Hi there,

I'm trying to work out how to run pytest-watch programatically, a bit like how this example of pytest is run here, so I can run it from within python,

https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/blob/master/runtests.py

The thing is, I don't think I understand how paths are treated by pytest-watch. I'm able to run the command above successfully, but when I try to use pytest-watch in a similar fashion, I'm getting an error along the lines of

ImportError: No module named 'settings'

pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.

In the code below, I am explicitly adding the django project to the python path with sys.path.insert(0, "examples/simple").

#!/usr/bin/env python
import os
import sys

import pytest

def main():
    from pytest_watch.command import main as pt_main

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.testing")
    sys.path.insert(0, "src")
    sys.path.insert(0, "examples/simple")

    pt_main()
    # return pytest.main('-x')

if __name__ == '__main__':
    sys.exit(main())

I've only really used pytest-watch as a consumer of it, but I'm up for having a go at making a PR if some extra code is needed to support it.

I could of course just be using it wrong - if this is the case, any chance of a pointer to see what I ought to be doing to get paths recognised properly?

Ta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant