Hey folks, I am moving multiple django microservi...
# general
g
Hey folks, I am moving multiple django microservices into a pants monorepo, so far I managed to get
runserver
working. Next is to get my tests working. So, any chance of getting my existing `APITestCase`s to run without a change? Running
./pants run src/python/worker/manage.py -- test
results in 0 discovered tests. If I specify the tests target
./pants run src/python/worker/manage.py -- test src/python/worker/app/tests
I get
No module named 'worker.app.tests'
I checked both the django sample and the django webinar, but unfortunately this project is running using pytest, and my microservices are not. nevertheless I tried running
./pants test src/python/worker/app/tests/test_api.py
but I think it won't work out of the box, I got the following:
Copy code
django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
What is is the shortest path to get my tests running?
p
Make sure you turn on the
string_imports
under
python-infer
option which will perhaps help pants infer deps from django strings used to specify python modules (apps, middleware, etc...) https://www.pantsbuild.org/docs/reference-python-infer#string_imports
you can also use the
dependencies
goal to see which deps pants is able to infer. For example
./pants dependencies src/python/worker/manage.py
or ``./pants dependencies src/python/worker/app/tests/test_api.py``
those will show direct dependencies, if you want to see transitive deps add the
--dependencies-transitive
option
g
string_imports
is enabled manage.py and tests/* don't have any dependency on each other. I tried to set some dependencies manually and got weird errors. Any recommendation?
I added
Copy code
python_tests(
    name="tests0",
    dependencies=[
        "src/python/worker:worker",
    ],
)
to my tests BUILD and now manage.py is showing as dependency, but still same DJANGO_SETTINGS_MODULE problem
I got them running by configuring pytest and conftest.py as per the github example, but everything is failing. One step closer!
t
@glamorous-nail-59544 Just curious if you figured it out. I ran into the same issue where the pytest vscode extension picked up the tests when `DJANGO_SETTINGS_MODULE`is set, but pants couldn't find the module.
g
@tall-plastic-15186 yes I have it running now. As mentioned before, following pytest configs here made it work, and tests were failing due to misconfigured assets dependencies.