How to run included tests on deployed pylons application - python

I have installed pylons based application from egg, so it sits somewhere under /usr/lib/python2.5/site-packages. I see that the tests are packaged too and I would like to run them (to catch a problem that shows up on deployed application but not on development version).
So how do I run them? Doing "nosetests" from directory containing only test.ini and development.ini gives an error about nonexistent test.ini under site-packages.

Straight from the horse's mouth:
Install nose: easy_install -W nose.
Run nose: nosetests --with-pylons=test.ini OR python setup.py nosetests
To run "python setup.py nosetests" you need to have a [nosetests] block in your setup.cfg looking like this:
[nosetests]
verbose=True
verbosity=2
with-pylons=test.ini
detailed-errors=1
with-doctest=True

Related

When running Django tests using Travis CI, my tests are running and completing locally, but are not running (or being found) remotely

As per the question, I have two tests which I am running successfully on my local machine. Running "python manage.py test" in the command line produces the following output:
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..
----------------------------------------------------------------------
Ran 2 tests in 0.495s
OK
Destroying test database for alias 'default'...
These tests are part of a project which is currently residing in a GitHub repository. This repository is linked to Travis CI, and as such, a travis.yml file can be found in the repository's root directory. The contents of the file are as follows:
language: python
install:
- python -m pip install -r requirements.txt
before_script:
- cd TNI_Project
script:
- python manage.py test
For reference, the "TNI_Project" directory is the one which contains the "manage.py" file, and the "requirements.txt" file contains the output of pip freeze.
However, once the build is launched on Travis CI, the build exits with 0, but none of the tests are run. The exact output can be found below:
$ python -m pip install -r requirements.txt
before_script
0.00s$ cd TNI_Project
0.41s$ python manage.py test
System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
The command "python manage.py test" exited with 0.
Done. Your build exited with 0.
Since the build actually completes without errors, this means that the actual problem lies in how Travis CI is unable to find my tests on the virtual machine. I can't seem to figure out why this is the case, and how to get the tests running remotely.
Any help would be appreciated!

Django+Heroku: compilemessages works but not MY translation file.

I find myself in a very weird situation:
I do not have my .mo files committed into my repo. I plan to generate them after I deploy
I installed the gettext buildpack availabe at https://github.com/piotras/heroku-buildpack-gettext.git
So this are the steps I did:
Deploy to heroku.
Run heroku run python manage,py compilemessages
This is being outputted:
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/ru/LC_MESSAGES
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/cy/LC_MESSAGES
processing file django.po in /app/prometheus/locale/zh_hans/LC_MESSAGES
processing file django.po in /app/.heroku/python/lib/python3.6/site-packages/django/contrib/gis/locale/sk/LC_MESSAGES
List one of files: heroku run ls /app/.heroku/python/lib/python3.6/site-packages/django/contrib/redirects/locale/zh_Hans/LC_MESSAGES RESULTS: django.mo django.po
List our file: heroku run ls /app/prometheus/locale/zh_hans/LC_MESSAGES/
RESULTS: django.po
django.mo is missing.
I ran python manage.py shell to see if I have some variables wrong:
heroku run python manage.py shell
In [1]: from django from django.conf import settings
In [3]: print(settings.BASE_DIR)
/app/prometheus
In [4]: print(settings.LOCALE_PATHS)
('/app/prometheus/locale',)
So i have no idea why my django.mo file is not being generated.
Any guesses?
Since Heroku 20, gettext is automatically added for the default Python build package. This is only during build and not at runtime. Therefore the command should be executed just after build.
Luckily this can be done using the post compile file in bin/post_compile (no extension like procfile) with the following line:
python manage.py compilemessages
Optionally you can add the specific language (e.g. python manage.py compilemessages -l nl)
Since Heroku automatically adds gettext, there is no more need to add additional build packs (at least for gettext) like the one from Piotras mentioned above.
These files are generated in the build phase and will be part of the compressed image. Therefore they should not be deleted afterwards.
TL;DR: Django.mo is generated and then deleted.
I'm in the same situation and tried to generate the files with
$ heroku run django-admin compilemessages
$ heroku run ls locale/LANG/LC_MESSAGES/
django.po
I didn't want to wait for connecting to Heroku on every command and used
$ heroku run "django-admin compilemessages; ls locale/LANG/LC_MESSAGES/"
django.mo django.po
$ heroku run ls locale/LANG/LC_MESSAGES/
django.po
Turns out, django.mo is created but for some reason it is immediately deleted.
Googling this gives Heroku Help -page Why are my file uploads missing/deleted?:
The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy.
What happens is
heroku run COMMAND
starts a new dyno, runs the command in it and shuts down the dyno once the command has exited, so all the files the command created are deleted.
As far as I know, options are either to commit the .mo-files to repo or serve them from storage, for example S3.

webpack and django on Heroku: bundling before collectstatic

I am building a django+react app on Heroku, using django-npm which automatically installs all modules from package.json to node-modules dir and then copies everything to staticfiles/ during python manage.py collectstatic (which is triggered by Heroku during deploy).
However, for this configuration to work I need to pre-bundle my React app before deployment and put it into my static folder along with all the CSS, fonts, etc. to be picked up by collectstatic later.
But I don't want to pollute my git diffs with new bundle versions. So, is there a way to make webpack create a bundle during deployment?
I know there is a release command on Heroku where I can put my npm run build. But the problem is it only fires AFTER collectstatic, so my bundle will only be created in static/ folder after this folder is scanned, and won't get copied to staticfiles dir.
Update:
Using bin/pre_compile should no longer be necessary as of March 11, 2019. Heroku will now automatically call an app's build script (if defined in package.json) during Heroku's build process. Source: Heroku Changelog.
Original: You can accomplish this with the (undocumented) pre_compile hook exposed by the heroku/python buildpack.
Add an executable shell file named bin/pre_compile at the top level of your app and it will be called automatically as part of the build process.
cd my-django-app
mkdir bin
echo '#!/usr/bin/env bash' >> bin/pre_compile
echo 'npm run build' >> bin/pre_compile
chmod +x bin/pre_compile

Issues in initial setup for django project

I am learning Django from the official documentation and while going through the tutorial at https://docs.djangoproject.com/en/1.7/intro/tutorial01/, I am stuck at creating a project part.
When I run django-admin.py startproject mysite I am getting following error
C:\Python34>django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--no-color Don't colorize the command output.
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
syncdb
test
testserver
validate
Note that only Django core commands are listed as settings are not properly configured
error: Requested setting INSTALLED_APPS, but settings are not configured
. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
I am using Python 3.4.1 and django 1.7. I don't have any other Django version installed and this is the first project I am creating.
You can just run django-admin startproject mysite(Note: not django-admin.py), because if you install django by pip, a executable program named 'django-admin.exe' will be added to 'C:\Python34\Scripts', which is already in your environment variable 'PATH' normally(if not, add it to PATH).
I was facing the same issue while installing Django 2.0.5. This can be resolved using Virtual Environments.
Environment details:
Python version: 3.6
OS: Ubuntu 18.xx.x
Steps:
Install Virtual Environment
pip install virtualenv
Create a Virtual work-space('VEnv')
virtualenv --python=python3 VEnv
Activate the Virtual Environment:
cd VEnv/
source bin/activate
Install Django(Version - 2.0.5)
pip install django==2.0.5
Create Project (Project Name: HelloDot)
django-admin startproject HelloDot
Run the server as below and then access it from "http://127.0.0.1:8000/"
cd HelloDot/
python manage.py runserver 8000
For more details, take a look at this: https://www.howtoforge.com/tutorial/how-to-install-django-on-ubuntu/
Make sure that you follow the troubleshooting guide because it looks like you don't have django-admin.py on your system path correctly. From the docs:
django-admin.py should be on your system path if you installed Django
via python setup.py. If it’s not on your path, you can find it in
site-packages/django/bin, where site-packages is a directory within
your Python installation. Consider symlinking to django-admin.py from
some place on your path, such as /usr/local/bin.
You should also use a virtualenv for each of your projects to allow isolation of dependencies per project and easier management of them. virtualenvwrapper is a useful tool for creating and managing your virtualenvs.

gunicorn running django on virtual env

I'm following tutorial from http://www.marinamele.com/2013/12/how-to-set-django-app-on-heroku-part-i.html and I can't pass the section with foreman -> guicorn configuration. My django app is in myproject directory.
When I'm trying to run command from my virtualenv, console freeze, but django app works in my browser - but foreman can't work properly
(myenv) ... gunicorn myproject.wsgi
But when I run:
(myenv) ... gunicorn myproject:wsgi
I got Failed to find application: 'myproject'.
my requirements.txt:
Django==1.6.5
argparse==1.2.1
gunicorn==19.0.0
wsgiref==0.1.2
this might of some help;
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/gunicorn/
especially below 2 lines
This requires that your project be on the Python path; the simplest way to ensure that is to run this command from the same directory as your manage.py file

Categories