How to get Eclipse + PyDev + App Engine + Unit testing to work? - python

I want to run my unit tests for a Python Google App Engine project using
Run As => Python unit-test
But when I try that all my Model tests bail with the error message:
BadArgumentError: app must not be empty.
Anyone got this to work?
NB: The tests runs fine using Nose --with-gae. But I want the PyDev integration with hyperlinking of resources and such.

Pasting the answer I got from the Fabioz (the PyDev creator) himself over at the PyDev forums on SF: https://sourceforge.net/projects/pydev/forums/forum/293649/topic/3618848
There's no such option right now... please enter a feature request for that. Note that you can run nose itself from inside of pydev (with the --with-gae option) -- which at least would give you hyperlinking inside of pydev -- to do that just create a custom run where nose is the main script.
Indeed, that's what I did and it works as advertised. I also entered that feature request. You can help by pushing your support behind the request: https://sourceforge.net/tracker/?func=detail&aid=2974043&group_id=85796&atid=577332

Related

How can I use debugger with unit test in Python with Pycharm?

I have the following problem :
I am doing some unit tests but the problem is that I cannot use the debugger I tried to click on "Debug namefile" using a breakpoint but it does not work. Alternatively, I tried to use tyhe following decorator #override_settings(DEBUG=True) but once again I had no result using this way.
I precise that it is only with unit tests I have this kind of problems. The other part of the code works well.
Could you help me please ?
PS: to do the unit test I imported TestCase from django.test.
Thank you very much !
I used to have same problem with PyCharm+Django when running python manage.py test from command line. I solved it by creating new configuration for test.
Mainly, you will need to fill "Script path" (path to manage.py) and "Parameters".
Then, run debug with that configuration and breakpoints in Django tests will work.
PyCharm menu:
Run / Edit configuration / Add Django test / Add Target and options.
For example, here is a mapping from command line to GUI fields,
Run just one test method
./manage.py test --keepdb animals.tests.AnimalTestCase.test_animals_can_speak
Target: animals.tests.AnimalTestCase.test_animals_can_speak
options: --keepdb
.
Ref, https://www.jetbrains.com/help/pycharm/2020.1/run-debug-configuration-django-test.html

Disable coverage while running nosetests

I'm new to Python. I am new to PyCharm.
I am trying to debug through my unit tests. They are done with nosetest.
Currently, when I run my tests with the vagrant debugger, it gives me the following complaint:
PYDEV DEBUGGER WARNING:
sys.settrace() should not be used when the debugger is being used.
This may cause the debugger to stop working correctly.
If this is needed, please check:
http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html
to see how to restore the debug tracing back correctly.
Call Location:
File "C:\Python27\lib\site-packages\coverage\collector.py", line 248, in
_installation_trace
sys.settrace(None)
Just going off the call location, I am assuming it does some manner of coverage while running and that the PyCharm debugger does not get along with the coverage library that nosetest is running.
If I run 'nosetests --plugins', I get the following output:
Plugin capture
Plugin failuredetail
Plugin xunit
Plugin deprecated
Plugin skip
Plugin multiprocess
Plugin logcapture
Plugin xcoverage
Plugin coverage
Plugin attributeselector
Plugin doctest
Plugin profile
Plugin id
Plugin allmodules
Plugin collect-only
Plugin isolation
Plugin pdb
Plugin timer
Is there a way to turn off coverage for my test run while I debug?
pytest-coverage does not work with Pycharm - use the --no-cov parameter in the PyCharm test runners. If you want the coverage in then use the PyCharm's coverage runner (with the --no-cov parameter) to use the coverage that comes with PyCharm.

Django unit test suite "--functions=" couldn't be empty

I'm upgrading a Django app from version 1.10.7 to 1.11.2.
After the upgrade, runserver command works well, but when I try to run the unit test suite the following error raised:
CommandError: Option `--functions=...` couldn't be empty
To run the unit test suite, I'm using the following command:
python src\main\manage.py test --noinput
As you can see, I'm not using any --function parameter and this is the same command that I used before the upgrade.
I reach the same situation if I run the test suite specifying the file to run.
I have also tried to run the help function for the manage command and no --functions parameter is showed.
I'm a little bit confused on this issue, and I don't find any information about this error in both, documentation and release notes.
Anyone knows how this error is raised and how to fix it?
I'm running Django 1.11.2 and Python 2.7
Thanks in advance
It looks like you've got a custom management command called check that conflicts with one of Django's built-in commands. For whatever reason, manage.py test is calling your custom command instead of the built-in one.
Renaming your custom command to something that doesn't conflict should solve the problem.

Can robot framework keyword can be executed in python console?

I am using robot framework for writing test case. As it is not possible to debug the each and every statement, logging is only way which makes it very slow to develop test case.
I am looking for a way in i can execute the robot keyword in python console. so that I can debug and see if the keyword i have created or inbuilt keyword that i have used will work correctly.
Is there a way to do it ?
eg. Can i execute wait until page contains element ${ELEMENT}?
Try following plugin on eclipse IDE, it allows you to put a break point and execute step by step.
The last time I checked (couple of months back) it was having few issue with importing existing project and running. I hope they all have been fixed.
https://github.com/nokia/RED
With RED Robot Editor (based on Eclipse) you can run your Robot testcases with debugger. This works the same as other IDE debugger - place breakpoint on executable row (line which consists RF keywords as this is limitation from Robot itself), than you can use step into,step over,variable view&change etc.
If you need to run debugger on Robot and Python level you can use PyDevD (pydev debugger) for python part.
Robot debug: http://nokia.github.io/RED/help/user_guide/launching/debug.html
Robot&Python debug: http://nokia.github.io/RED/help/user_guide/launching/robot_python_debug.html

Debug Pylons application through Eclipse

I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?
Create a new launch configuration (Python Run)
Main tab
Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory)
Don't forget to add the root folder of your application in the PYTHONPATH zone
Arguments
Set the base directory to the root folder also.
As Program Arguments use "serve development.ini" (or whatever you use to debug your app")
Common Tab
Check allocate console and launch in background
If you'd rather not include your Python installation in your project's workspace to get paster, you can create a pure-Python driver like:
#!/usr/bin/env python
from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])
...and run/debug that in Eclipse.
Note: this is running without the --reload option, so you don't get hot deploys (i.e., you'll need to reload server to see changes). Alternatively, you can add the --reload option to get hot deploys, but then Pydev won't stop at your breakpoints. Can't have your cake and eat it too...
ServeCommand("serve").run(["--reload", "development.ini"])
yanjost has it right, just wanted to add that you need to make sure you do not use the --reload option, this will prevent the debugger from properly attaching itself and cause your breakpoints not to work. Just a little thing I ran in to.
I was able to get --reload working by changing the 'Working directory' in the arguments tab to not use default (i.e. select 'Other'->File System->'Root of your Pylons' app where development.ini is stored.
On linux that will probably be /usr/bin/paster or /usr/local/bin/paster for paste script, and for arguments i have: serve ${workspace_loc}${project_path}/development.ini
I also got this working (finally). I used buildout instead of virtualenv to install pylons (instructions at: http://wiki.pylonshq.com/display/pylonscommunity/Howto+install+Pylons+with+buildout), so the instructions above needed to be changed a little as far as the paths go.
-for "Main Module", I use:
${workspace_loc:myeclipseprojectname/bin/paster}
(adding --reload made breakpoints not work for me, and I tested this a couple times)
-for "Program Arguments", I use:
serve ${workspace_loc:myeclipseprojectname/mypylonsprojectname/development.ini}
-for "Working Directory, Other:", I use:
${workspace_loc:myeclipseprojectname/mypylonsprojectname}
-as mentioned above, in "Common Tab", "Check allocate console and launch in background"
-and remember to set a breakpoint before trying.
This doesn't really answer question about how to do it in eclipse. But I've been debugging paster server with winpdb, which is quite nice graphical python debugger (you can install it with easy_install winpdb).
Just start your server e.g.:
winpdb /usr/local/bin/paster serve development.ini
And click run button.
As wayne said, it's necessary to not use --reload option. At least I wasn't able to find how to attach to actual webapp even, when selecting to which forked process debugger should enter (entering different processes can be controlled with "fork parent" and "fork child" debugger commands).

Categories

Resources