I have project in django 1.4 and I need to run django test in contious integration system (GitLab 6.8.1 with Gitlab CI 4.3).
Gitlab Runner have installed on server with project.
When I run:
cd project/app/ && ./runtest.sh test some_app
I get:
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named django.core.management
How I may run tests?
Do you have Django installed on the testrunner?
If not, try to configure a virtualenv for your testsuite. Best might be (if you have changing requirements) to make the setup and installation of this virtualenv part of your testsuite.
Change your job script in gitlab-ci with the following:
#!/bin/bash
export DISPLAY=:10
virtualenv env
source env/bin/activate
pip install -r requirements.txt
python manage.py test
Before doing this,. install virtualenv and xvfb (for selenium test) for GitLab runners.
Related
I am trying to use aws_cdk in my project.
I am using visual studio as a IDE and I setup my virtualenv doing this:
Install https://nodejs.org/en/.
Through npm, install cdk from cmd window: npm install -g aws-cdk
Install python3
Using terminal in Visual Studio Code: go to the project folder
Run python -m venv .venv to create the virtual env.
Activate it: source .venv/bin/activate
Run pip install: pip install -r requirements.txt
Run another pip install: pip install -r requirements-dev.txt.
Check with cdk diff in the cmd
This last step returns:
Traceback (most recent call last):
File "C:......\app.py", line 4, in <module>
import aws_cdk as cdk
ModuleNotFoundError: No module named 'aws_cdk'
My App.py looks like this:
#!/usr/bin/env python3
import os
import aws_cdk as cdk
import module_config
from myproject.myproject_stack import MyStack
app = cdk.App()
tags = module_config.with_tags(service_name="my_project")
prefix = module_config.with_prefix(service_name="my_project")
MyStack(
app,
construct_id=prefix,
prefix=prefix,
tags=tags,
env=module_config.env,
)
app.synth()
My requirements.txt looks like:
aws-cdk-lib==2.56.1
constructs>=10.0.0,<11.0.0
The requirement-dev.txt is:
bandit>=1.7.4
black>=22.10.0
coverage>=6.4.4
pylint==2.15.5
pytest
pytest-cov
yamllint
pre-commit
If in the vistual studio I do ctrl+mouse click it opens the aws-cdk code, therefore I know it is installed, but seems like the virtual env is not able to find it.
In my local repository, the folder .venv has a folder Lib\site-packages and this one has another called aws_cdk.
I see everything corret, but when running the cdk diff it breaks.
I'm trying to make an open source contribution to a python module that is hosted on Github (pypika).
I cloned the repo from github and ran pip in editable install mode such that any future imports would point to my version of the code.
But when I try running a test file within the repo, I get an error when trying to import the module. What am I doing wrong? How can I make it so that the import will use the modified module that I'm working on?
$ cd Dev
$ git clone https://github.com/kayak/pypika.git
$ pip install -e /Users/me/Dev/pypika
Obtaining file:///Users/me/Dev/pypika
Installing collected packages: PyPika
Running setup.py develop for PyPika
Successfully installed PyPika
$ python3 ./pypika/pypika/tests/test_functions.py
Traceback (most recent call last):
File "./pypika/pypika/tests/test_functions.py", line 3, in <module>
from pypika import (
ImportError: No module named 'pypika'
PyPika maintainer here. In order to contribute it's best to make a fork on Github and put your contributions in a separate branch which you can then pull request.
In order to run the tests you simply need to execute python -m unittest in the project folder of PyPika. (Or use the Python test runner functionality of your favourite IDE.)
pip install -e /Users/me/Dev/pypika will work if executed in the environment of the project in which you want to use PyPika.
Im trying to run a package wal-e which I have installed as user root with sudo python3 -m pip install wal-e[aws,azure,google,swift].
I can run this command perfectly as user root using envdir /etc/wal-e.d/env wal-e backup-fetch /var/lib/postgresql/9.6/main LATEST.
However, when I sudo su - postgres and then run envdir /etc/wal-e.d/env wal-e backup-fetch /var/lib/postgresql/9.6/main LATEST, I get the error
Traceback (most recent call last):
File "/usr/local/bin/wal-e", line 7, in <module>
from wal_e.cmd import main
ImportError: No module named 'wal_e.cmd'
I gave user postgres full sudo permissions with usermod -aG sudo postgres. Also the wal-e package is installed in the same location.
When I run ls -la I get
-rwxr-xr-x 1 root root 211 Sep 20 14:24 /usr/local/bin/wal-e
Im also on Ubuntu 16.04.3
How can I run the command just like the root user?
I had to run a strict setup process for wal-e in order for the package to function properly.
Virtually what it boiled down to was installing all necessary dependencies on the machine that I was working with before installing and creating the user postgres. If the user was created before all the dependencies were installed, I got permissions errors.
I can not understand how to create .po and .mo files to use translation in my GAE project. I found django-admin.py at /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/bin/django-admin.py, but if I run it as python django-admin.py, then I get
Traceback (most recent call last):
File "django-admin.py", line 2, in <module>
from django.core import management
ImportError: No module named django.core
Ok, the following helped to start working with localization -
export PYTHONPATH="$PYTHONPATH:/usr/local/google_appengine/lib/django-1.5"
brew install gettext
brew link gettext --force
mkdir conf
mkdir conf/locale
python /usr/local/google_appengine/lib/django-1.5/django/bin/django-admin.py makemessages -l ru
(btw, here is good, but old article about django translation usage with GAE; see also this article)
Im using the following travis-ci configuration
language: python
env:
- DJANGO=1.4
- DJANGO=1.5
- DJANGO=1.6
python:
- "2.6"
- "2.7"
install:
- sudo pip install Django==$DJANGO
- sudo pip install .
script:
- cd autotest
- python manage.py test ...
But in everytime the tests are executed, I run into the following issue:
$ python manage.py test ...
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
The command "python manage.py test ..." exited with 1.
As i said on irc,
You are running pip install as root. More than that, sudo will reset the environment before finding and running pip. This will mean your pip install is not into the virtualenv that travis provides, but into the global site-packages.
When you do python manage.py test you are using the python binary provided by a virtualenv. However virtualenv will not look in the system site-packages. So it cannot see the Django you installed into the system site-packages.