Name:
[002] Ian Ozsvald
Member:
90 months
Authored:
181 videos
Description:
I am the co-founder of ShowMeDo (see http://showmedo.com/about), author of `The Screencasting Handbook <http://thescreencastinghandbook.com>`_ and the founder of the professional screencast production company `ProCasts <http://procasts.co.uk>`_:
.. image:: http://procasts.co.uk/media/procasts_sma ...
Starting with Unit-tests [ID:250] (9/17)
in series: Python 101 - easygui and csv
video tutorial by Ian Ozsvald, added 05/07
Name:
[002] Ian Ozsvald
Member:
90 months
Authored:
181 videos
Description:
I am the co-founder of ShowMeDo (see http://showmedo.com/about), author of `The Screencasting Handbook <http://thescreencastinghandbook.com>`_ and the founder of the professional screencast production ...
Our authors tell us that feedback from you is a big motivator. Please take a few moments to let them know what you think of their work.
Unit-tests are an invaluable development tool and should be a part of every developer's toolkit. Not only do they help us to test that our code works as expected, they also help us to write good code in the first place and point out errors that are introduced later in the development cycle.
Here we test that the nosetests environment is installed and running before we go on to write tests for our code in the following episodes.
We also look at this special piece of code 'if __name__ == '__main__':' which lets us unit-test just our functions.
Assumptions: nosetests is already installed on your machine. This wiki page describes how to install nosetests. The Python Development series also covers the use of nosetests in this episode.
Task: make testCSVReader.py and test that nosetests works
Created May 2007, running time 7 minutes.
#import csvReader
def test1():
pass
- python
- beginners
- tutorials
- beginner_programming
- code
- time
- running
- episodes
- application
- graphics
- files
- part
- make
- screencasts
- first
- development
- help
- tools
- user
- work
- look
- builds
- IDE
- useful
- cover
- wiki
- learning
- functions
- modules
- programmers
- pages
- good
- read
- test
- interfaces
- values
- install
- problem
- wing
- environment
- debugging
- nosetests
- starting
- messages
- complete
- wingware
- easygui
- developers
- keep
Got any questions?
Get answers in the ShowMeDo Learners Google Group.
Video statistics:
- Video's rank shown in the most popular listing
- Video plays: 393 (since July 30th)
- Plays in last week: 0
- Published: 72 months ago
Thank-yous, questions and comments
If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?
You may also want to see our ShowMeDo Google Group to speak to our active users and authors.
All comments excluding tick-boxed quick-comments
Without these video tutorials I am quite certain I would not have learned about several of these tools such as 'nosetests' for some time - and it would take quite a lot longer to figure out how to use them. Thanks.
Starting with Unit-tests (9/17)
1:20 start names with test e.g. testCsvReader
2:50 use 1/0 (one divided by zero) for test failure
5:30 if __name__ == "__main__": to suppress function calls
Resources:
thanks. good explanation of TDD
beaon,
I'll jump in and answer your question. __name__ is one of Python's many special names. In code that is imported from another program and ran, __name__ is the name of the module, but it is '__main__' when it is the program which was ran.
One common thing done is to put the code that runs the program in a function:
def main():
.... code here
if __name__ == '__main__':
main()
Thus, if desired, we can run the program when it is imported ( modulename.main() ) and it also runs when this is program ran.
This is great,
Can you clarify how the __name__ variable works?
Does the __name__ variable take the value of the .py file that ran it? How does it match __main__ only when csvReader.py is run? Any clarification or links to documentation you can provide would be rockin. Thanks!
This is great,
Can you clarify how the __name__ variable works?
Does the __name__ variable take the value of the .py file that ran it? How does it match __main__ only when csvReader.py is run? Any clarification or links to documentation you can provide would be rockin. Thanks!
I have tried to set up nose test, but I fail every time. I tried looking at Ian's introduction to unit testing in the Python on XP series, but no luck. Any quick hints? P.s. I am running on Win XP.
Since Python 2.6 has the unittest module, is it better to use unittest if one has Python 2.6 rather than nosetests?
Once again python frustrates until I figure out that I didn't properly indent the code. Great tool, great lesson!
Hi Erik. I've replied via email, I think they've checked in a bad build of 'nose'. Your install method (easy_install nose) is correct and I used it just a few weeks ago on my Windows XP laptop.
Let's wait a day and see if they checkin a better build, if not I'll have a look around on your behalf.
Ian.
I got completely lost in the easy_install and nose event
Hi Ryan...the video here runs for 7:32. Perhaps you have a badly cached copy? You might want to try flushing your cache (in Firefox use Tools|Clear Private Date) so that the video-player's private cache is cleared.
Re. a module/script - a 'script' *is* a 'module'. Python just calls a file containing Python code a 'module'. It is just a naming convention.
Ian.
Now we are getting someone - some really intermediate/advanced computer programmer (in my opinion anyways). Unit-test seem like an excellent way to test codes samples. Just wondering, how do you make a script a module, or does it do it automatically.
The video seems to cut off around the 5 minute mark.
Sorry, my mistake, the link in the above description was wrong. Now it correctly points at 'Unit Tests for Dependable Code':
http://showmedo.com/videos/video?name=pythonOzsvaldPyNewbie8&fromSeriesID=49
As you found, the instructions are in the wiki here:
http://wiki.showmedo.com/index.php/PythonOzsvaldNewbiesXPSeries#Installing_nosetests
Ian.
the link to how to install nosetests would be where? Used google and found this -
http://wiki.showmedo.com/index.php/PythonOzsvaldPyNewbieSeries
