Open felipeochoa opened 6 years ago
Actually, even fixing this doesn't resolve the core issue since the following s-trim
call will still fail.
And there a couple more issues around here:
elpy-django--get-test-format
calls the non-existent elpy--get-django-test-runner
in case of errorcompilation-environment
is not used in this check, which closes off an easy way of doing per-file/buffer/project configuration that previously workedHere's a better version of get-test-runner:
(defun elpy-django--get-test-runner ()
"Return the name of the django test runner.
Needs `DJANGO_SETTINGS_MODULE' to be set in order to work."
(let* ((process-environment (append compilation-environment process-environment))
(django-import-cmd "import django;django.setup();from django.conf import settings;print(settings.TEST_RUNNER, end=\"\")")
(django-settings-env (getenv "DJANGO_SETTINGS_MODULE"))
(default-directory (elpy-project-root)))
;; If no Django settings has been set, then nothing will work. Warn user
(when (not django-settings-env)
(error "Please set environment variable `DJANGO_SETTINGS_MODULE' if you'd like to run the test runner"))
(with-temp-buffer
;; We have to be able to import the DJANGO_SETTINGS_MODULE
;; A non-zero exit code will indicate an error importing django settings
(unless (zerop (process-file-shell-command
(format "%s -c '%s'" elpy-rpc-python-command django-import-cmd)
nil '(t nil)))
(error (format "Unable to import DJANGO_SETTINGS_MODULE: '%s'" django-settings-env)))
;; Return the last line of output, which has the fully qualified name of the test runner to use
(forward-line 0)
(buffer-substring-no-properties (point) (point-max)))))
Sorry I can't package this into a PR with tests, but hopefully this helps solve the issue. This also has the benefit of only shelling out to python once
Thanks for the snippet, i'll look at it on the weekend.
Summary
1291 broke
elpy-test
for my Django project. My project prints a single line to stdout while loading the logging configuration, so this check incorrectly reports that the module cannot be imported.Steps to reproduce
print("hi")
to your settings fileelpy-test
in that projectResult of
(elpy-config)
I don't have time right now to submit a PR, but I think changing the check to be:
should fix this issue