is there a way to get django tests + buildout run well integrated with Eclipse/Aptana? - django

it's fairly easy to set up Eclipse to run a django project's tests created with django-admin startprojects, we whould just point a Run command to ./manage.py, and supply the necessary arguments.
but what can I do if a project is built using buildout?
of course, bin/biuldout creates the handy bin/test-1.1 and bin/test-trunk files, but these are not integrated with eclipse
I can even run these as an external tool from Eclipse, but how can I get the nice code recognition of running manage.py test myapp?
does anyone know a solution? is there some buildout recipe that allows me to do this?
thanks for your help!

I'm assuming you use the djangorecipe recipe (http://pypi.python.org/pypi/djangorecipe)?
In that case, why can you apparently run "manage.py test myapp" and why can't you run "bin/django test myapp"? (Or "bin/test" for that matter)?
I suppose you have to configure that manage.py call somewhere, so why can't you configure bin/django in the same way? In the end, bin/django is just a python script, too. Have you tried calling it in the same way as manage.py?

Related

What Build Step should be used for running QUnit tests in TeamCity?

I've got a TeamCity build configuration with two steps currently:
MSBuild
Execute powershell sciprt
I want to add another one:
Run QUnit tests
Inside Visual Studio I use Chutzpah to run my QUnit tests. It seems that there is no "Runner type" appropriate though for QUnit tests, and because I do see one for NUnit I'm left wondering if I'm looking at this right.
Should I get a TeamCity extension to add a "Runner type" for QUnit tests? Should I create a powershell script that runs chutzpah-console? And if so how should I make sure the test output is picked up by TeamCity (do I need the /nunit2 or /junit flag?)?
I've done some research, allow me to share...
I've applied my Google-fu but that leads to a blog post with complicated QUnit tests with special TeamCity messages (or perhaps I misunderstood?) and a blog post on using a command-line build step to call PhantomJS that uses a rather contrived html file that seems like overkill to me if I'm already using Chutzpah in Visual Studio anyways (or perhaps I misunderstood)?
I've gone through the Chutzpah Full Documentation but as far as CI goes it only has a section on TFS Build, nothing on TeamCity or CI in general. I've carefully looked through the command line options documentation, and it does have one relevant option:
/teamcity :Forces TeamCity mode (normally auto-detected)
This suggests that you normally don't need to do anything to get things working, but that's certainly not the case: my sln (or better: csproj) contains several js files with QUnit tests, but TeamCity shows no tests.
So, how do I get TeamCity to run QUnit tests in the (c)leanest way possible / how do I use Chutzpah in a TeamCity build step?
No need for "service messges" or custom html files that go into a special PhantomJS call if you're already using Chutzpah. Here's one (other) way to do it in a (c)lean way.
There is no specific runner type for this type of build step. But no need for a custom Powershell script either: it'll be one line of script only. You can just use a Command Line step to invoke Chutzpah. To be more complete, assuming you've got TeamCity running already on a Windows machine, follow these steps:
Install chutzpah.console.exe. The easiest way is probably using chocolatey to install the Chutzpah package using this command in Powershell:
choco install chutzpah
This installs Chutzpah and makes sure the exe is in your path (you may need to reboot TeamCity parts to get this noticed!).
Note that alternatively you could also manually get chutzpah.console.exe on your CI server somehow (e.g. grab it from your dev machine) and reference it with a full path or place it in your path yourself.
Add a Command Line build step with a custom script like this:
chutzpah.console.exe "MyProject/UnitTestsSubDir"
E.g.:
And by some black magic this is all it takes: your tests will be run (see the build log) and TeamCity will pick up the test results.

How to configue Pydev test runner to use Docker

I am developing a Django app or two using pydev as my IDE. I like it a lot :) However, I recently got really excited about Docker and am using Docker and Fig to serve my application now. My problem is that I would like to run my tests in this build environment- seems like this is kinda the point after all!
I know how to actually do it.
fig run web python3 /code/manage.py test
would run the tests. If I didn't want to use the Django runner, I could run
fig run web python3 /code/myapp/tests.py
Either way though, I cannot figure out how to issue that command from the IDE. All of the run configurations point to the configured python.exe ... does anyone know if there is a way to replace that with a fully customized command?
Well, the PyDev launch configuration is really targeted towards running Python, but there are alternatives to running it through other ways:
Create an external tool run (run > external tools > external tools configuration): You should be able to run anything you want from there... the downside is that this isn't really integrated into PyDev, so, if you have stack-traces they won't be clickable (and you won't be able to debug either).
Create a launcher script which in turn uses subprocess to launch the command you want... if you redirect things tracebacks should be clickable. The downside is that you won't be able to create a debug session either -- but you can still use the remote debugging in this case (http://pydev.org/manual_adv_remote_debugger.html)
Improve PyDev to do that better... (i.e.: get the code: http://pydev.org/developers.html and add docker support to a project through fig -- it should be something close to org.python.pydev.django which has special integration for running in django -- with some tweaks to the start command line, even starting in debug mode directly can work here)... if you decide to go that route, you can create a feature request at https://sw-brainwy.rhcloud.com/tracker/PyDev/ and ask code-related stuff and I'll help :)
Possibly you can create a custom executable which acts like Python but in reality just forwards things to other places (i.e.: to fig run) -- I haven't actually tested this, but in theory it should work (in the past there was work to support dummy 'python' runners such as that -- i.e.: for supporting http://cctbx.sourceforge.net/ -- so, it should work -- but you still have to create this launcher script for your use case to pass things to fig run). If the work is done properly, the debugger could work here too.

Eclipse with Django Unittest

I have a simple set of Django test cases that fail in Eclipse. Specifically if I have something like:
resp =self.client.get('/accounts/newUser/')
self.assertEqual(resp.status_code,200)
self.assertTrue('user' in resp.context)
then it would fail because resp.context is None. I have managed to get to run from eclipse using django.test.utils.setup_test_environment(), but then I have have to do something like resp.context[0][0][0]['user'] which is less than ideal.
Is there a more clever way to get python unit tests to run from Eclipse? I've seen this solution using django-nose from eclipse and my original solution above came from here.

Is there a way to make aptana 3 autoreload when i make changes to a py file in a django project?

Aptana makes it open in --noreload mode automatically because not doing so causes python instances to remain open or something like that, is there anyway to bypass this problem?
As far as I know, it's not possible to auto-reload .py files within an Aptana Python run/debug configuration (which is what I'm assuming you're doing to get access to the call stack for debugging). I've been using Aptana for Python development for a couple of years, and I've yet to see a way to do this. if someone knows how, please share!

Debugging Django from the command-line

I'm working on debugging Django from the command-line. I'm working with django_extensions, and I have IPython installed and ideally I'd like to be able to extract as much information in the shell as possible. How would I go about this task most efficiently?
As mentioned by Geo manage.py shell is good but since you have django_extensions already installed then Carl's suggestion of manage.py shell_plus is even better... saves a ton of typing.
But, as a third suggestion that is a bit less general, you might also want to check out django-viewtools. I personally tend to use shell_plus, but this might be useful.
If you have django_extensions installed, use
python manage.py shell_plus
to get all of your model classes automatically pre-loaded.
How about:
python manage.py shell
More info here
My favorite ways of debuging django problems is using the ./manage runserver_plus command to the django_extensions. It uses the Werkzeug debuger, which gives you a python shell in the web browser itself. If you want a shell anywhere in the code, just type some bogus python, like a simple a, and you will get a shell when that code is executed.
Another nice tool is ipdb ipython debugger. Its the same as pdb but better (and uses ipython. With this, and runserver_plus, you can insert import ipdb; ipdb.set_trace(), and you will get a ipython shell with an debugger in the same window as you have runserver_plus.
Take a look at http://docs.python.org/library/pdb.html#debugger-commands for a list of commands you can use inside the debugger.