As much as the console runner is nice, I enjoy the instant red/green view of a graphical runner such as NUnit or MSTest for quickly glancing at broken tests.
Does such a tool exist for Eclipse? I've tried Google but only found some awful standalone versions.
PyDev has a feature to quickly execute the unit tests from withing the IDE. It also allows selecting the unit test cases to run. But it displays the usual textual output, no graphical representation of the test results.
The best solution I've ever seen (and actively used) is Wing IDE's Testing pane, which displays a tree of test results with output and traceback as needed. That's pretty usable, but not for Eclipse, unfortunately. I just mentioned this, because it might help you in some way or give you an idea on how to implement this for Eclipse in the future.
Related
I went through a few articles about how to setup VSCode to work with python for the first time, and I'm very confused.
To me, VSCode seems messy - so many json settings which I manually need to configure...
Anyway, I now have 3 ways of running my python script:
F5, which runs via the terminal
Run (Ctrl+Shift+D), via Watson
Run via Code Runner
I don't understand the differences between the different methods of running my script.
Can someone please give me a short intro?
Thanks!
Terminal:
Terminal is fast and efficient to use. It also provides detailed information about the errors in your programs. And it is widely used buy a lot of Python programmers.
Watson:
It provides developer tools for more advanced users. You can get more information about that from here. Not recommended for a beginner.
Code Runner:
Code runner is also used to see the the results of the programs but it is read only, and there can be some problems with that. As an example if you are building an application that takes the input from the user in Python, you can't do that via code runner.
So which one is the best?
I would recommend using the Terminal (F5), because it is good for small programs, you get detailed information about your apps, the problems with your apps and some other options too. It is also fast and easy to use for a beginner.
Hope it's clear now.
I am not a native English speaker. When I code with Python, I often make spelling mistakes and get 'NameError' Exceptions. Unit test can solve some problems but not all. Because one can hardly construct test cases which cover all logic. So I think a tool that detect such errors would help me a lot but I searched Google and cannot find it.
I believe that testing your code via a static analyzer (e.g. pylint) will help a lot.
Another hint: you can use a fancy IDE with smart auto-completion which will reduce the amount of such mistakes.
I prefer eclipse with pydev integration for python development projects.
It will solve your purpose and will show you the errors in RED before you run your program. but it requires your project to be properly configured under eclipse as below:
Configure Python interpreter after integrating PyDev with eclipse
Create / Import your project & set as python pydev project
Configure your source folder ( Give information to eclipse that which folders contains python source code under your entire project tree)
You're done & setup now for general python programming setup.
Further more you can integrate your Eclipse/Pydev project with pylint as mentioned by BasicWolf which checks your code quality & bugs on the go while you're coding.
References:
Installing PyDev under Eclise
Eclipse PyDev Integration
Troubleshooting PyDev/PyLint Integration
pylint can help here. It will report those locations as
E: 2,6: Undefined variable "foo"
for example.
You could get an IDE which helps a bit with autocompletion of names, though not in all situations. PyDev is one such IDE with autocompletion; PyCharm is another (not free).
Using autocomplete is probably your best bet to solve your problem in the long term. Even if you find a tool which attempts to correct such spelling errors, that will not solve the initial problem and will probably just cause new ones.
I use Notepad++ for writing and running Python scripts. It is a great text editor, except for debugging. Is there a way to step through the code, use break points, view variable values etc. in Notepad++ like you can in Visual Studio?
Does such a plug-in exist? Not that I know of. I agree completely with qor72 on that note.
Is it possible to create such a plugin / functionality? Possibly.
After doing some quick digging, I did find a plugin that looks promising, Python Script. In short it allows you to run python scripts that can access the NPP modules (file menus etc...) as well as the Scintilla Methods which appear to give access to things like the markers on the pages.
To accomplish such a feat I could see the task being broken into a few large blocks (I feel a new open-source project coming on...)
Using Python Script, integrate the python debugger(PDB) as mentioned by Shashi.
Using the Scintilla Methods, add trace back calls where a NPP marker is placed
Redirect PDB outputs and process them to show where the file is stopped (again using the Scintilla methods).
While at the newly created breakpoint and using PDB determine all of the variables in the current namespace. Take this info and dump it to a CMD window, or if you want to get fancy some GUI created with Tk / wxPython
Closing Thoughts
While I think it's possible to create such a plug in, it would be quite an undertaking. Along that line, you might be better off trying to find a different editor that has this built into it already and just create macros (or whatever the IDE calls them) to add in the things you like most about NPP.
Please note that I am a daily user of NPP and have been for many years so I definitely understand why you'd like to have the functionally added to NPP. One of my favorite things about NPP is the speed in which it opens and searches files... moving to a bloated IDE, IMO, would not be worth it to me.
My current work flow is to do all of my editing in NPP and just double click to run the modules. If it fails or goes off in the weeds, I launch IDLE to debug it.
I really hope someone tells me I'm wrong (I'd love to have that feature in Notepad++) but, Notepad++ is designed as a programmers editor, not an IDE. While it has a lot of cool functionality, that level of debugging isn't part of the core tool.
Not seeing anything in the npp-plugins either.
I think python debugger
is the best option if editor is not providing facility :)
Quick guide:
from pdb import set_trace as bp
code
code
bp()
code
code
At the (Pdb) prompt, enter s to step, p foo to print foo, and c to continue executing the code until hitting another breakpoint.
Have you thought of using Komodo.
It's open source and has ports for Windows, Linux and MAC (I think).
This may be an alternative, and if you want some advice from notepad++ users, have a look at the following post on this very site:
Komodo Edit and Notepad++ ::: Pros & Cons ::: Python dev
Some npp users here seemed to have made the switch for python editing running etc...
personally don't know much about debugging on Komodo but as it's an IDE so would be surprised if you couldn't do it easily
I don't really see why Shashi's answer hasn't been upvoted. For the link that he has given supplies a way to step through python scripts as the OP has requested.
So for all who don't know about the pdb module, upon importing it the pdb.set_trace() function allows one to step through the area of code after it. And it is very much similar to the visual studios method of debugging. While you're stepping through the code you are able to input a variety of commands.
One of them is p <expression> and that allows the user to print the current state of variables within the local and global scope.
I know it's 11 years on, and I'm a bit late to the game, and I know it's not Notepad++ but please do consider Visual Studio Code.
It's free, easy to install (both the editor itself plus any python interpreters it uses) and it's widely used and nowhere near as bloated as it's Visual Studio counterpart. It also appears to be the IDE of choice for a lot of Cisco-related course material.
Write your code, click to the left of code pane to insert your breakpoints click the Debugger icon (highlighted), and you're away:
I have a very large python project with a very large test suite. Recently we have decided to quantify the quality of our test-coverage.
I'm looking for a tool to automate the test coverage report generation. Ideally I'd like to have attractive, easy to read reports but I'd settle for less attractive reports if I could make it work quickly.
I've tried Nose, which is not good enough: It is incompatible with distribute / setuptools' namespace package feature. Unfortunately nose coverage will never work for us since we make abundant use of this feature. That's a real shame because Nose seems to work really nicely in Hudson (mostly)
As an alternative, I've heard that there's a way to do a Python coverage analysis in Eclipse, but I've not quite locked-down the perfect technique.
Any suggestions welcome!
FYI we use Python 2.4.4 on Windows XP 32bit
Have you tried using coverage.py? It underlies "nose coverage", but can be run perfectly well outside of nose if you need to.
If you run your tests with (hypothetically) python run_my_tests.py, then you can measure coverage with coverage run run_my_tests.py, then get HTML reports with coverage html.
From your description, I'm not sure what problem you had with nose, especially whether it was a nose issue, or a coverage.py issue. Provide some more details, and I'm sure we can work through them.
Ned has already mentioned his excellent coverage.py module.
If the problem you're having is something nose specific, you might want to consider using another test runner. I've used py.test along with the pytest_coverage plugin that lets you generate coverage statistics. It also has a pytest_nose plugin to help you migrate.
However, I don't understand exactly what the problem you're facing is. Can you elaborate a little on the "distribute / setuptools' namespace package feature" you mentioned? I'm curious to know what the problem is.
I'm writing quite a few unit tests and using nosetests to run them. Nose certainly makes it nice and easy to run tests, but the output can be pretty cluttered at the best of times, and a downright mess at others, depending on warnings and errors.
I was wondering if there are any visual tools that wrap nose so that the feedback cleaner. A results grid showing test names, run times and indicating success/failure status with colours would be a huge visual aide. Better still, if it could split up the error messages and tracebacks on a case by case basis, it would really cut down on the amount of clutter when a large number of tests fail on a major change.
This is starting to read like a wishlist, but does anything even close to this exist?
There's a very similar question here.
It doesn't look like there's a standardized GUI for nosetests (as in, standardized for just the python interface). There seems to be a few GUI plugins for nosetests depending on which IDE you're using - a quick search brought up this link for Komodo.
However, there are many other GUI based unit testing frameworks out there for Python - have you tried PyUnit?
Well, what you can do is to use the jenkins integration server, we use it with py.test and phpunit (it is really simple to use it with any other testing framework), it provides us some fancy (and useful!) graphs containing
Number of tests that run
Number of tests passing/failing
The stack trace for the failed tests
Execution times for tests
Code coverage for the tests
You can also relate it to git/svn/mercurial...
Here you have an example of how to configure hudson (for the record, jenkins is a fork of hudson, so the instructions are still valid :), in order to provide the elements from your wishlist.
An easier option is to use a IDE as PyCharm, it has integration with nosetests, and will tell you which tests passed/failed and its times, however, jenkis stores historical data.
Good luck :)
Have you taken a look at the Nose plugins page? A quick glance revealed at least a couple that stated they could provide a GUI interface.