Re: Unittest

2016-07-25 Thread Terry Reedy
On 7/25/2016 12:45 PM, Joaquin Alzola wrote: Hi Guys I have a question related to unittest. I suppose a SW that is going to live will not have any trace of unittest module along their code. In order to test idlelib, I had to a _utest=False (unittest = False) parameter to some functions. The

Re: Unittest

2016-07-25 Thread Ben Finney
Joaquin Alzola writes: > I suppose a SW that is going to live will not have any trace of > unittest module along their code. Many packages are deployed with their unit test suite. The files don't occupy much space, don't interfere with the running of the program, and can be helpful to run the te

Re: Unittest

2016-07-25 Thread Brendan Abel
Generally, all your unittests will be inside a "tests" directory that lives outside your package directory. That directory will be excluded when you build or install your project using your setup.py script. Take a look at some popular 3rd party python packages to see how they structure their proj

Re: unittest weirdness

2014-04-30 Thread Ethan Furman
On 03/11/2014 01:58 PM, Ethan Furman wrote: So I finally got enough data and enough of an understanding to write some unit tests for my code. The weird behavior I'm getting: - when a test fails, I get the E or F, but no summary at the end (if the failure occurs in setUpClass before

Re: unittest weirdness

2014-03-12 Thread Terry Reedy
On 3/12/2014 11:32 AM, Ethan Furman wrote: I strongly suspect it's memory. When I originally wrote the code I tried to include six months worth of EoM data, but had to back it down to three as my process kept mysteriously dying at four or more months. There must be waaay too much stuff bein

Re: unittest weirdness

2014-03-12 Thread Ethan Furman
On 03/12/2014 04:38 PM, Steven D'Aprano wrote: [snip lots of good advice for unit testing] I was just removing the Personally Identifiable Information. Each test is pulling a payment from a batch of payments, so the first couple asserts are simply making sure I have the payment I think I hav

Re: unittest weirdness

2014-03-12 Thread Ethan Furman
On 03/12/2014 04:47 PM, Steven D'Aprano wrote: top -Mm -d 0.5 Cool, thanks! -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
On Wed, 12 Mar 2014 08:32:29 -0700, Ethan Furman wrote: >> Some systems have an oom (Out Of Memory) process killer, which nukes >> (semi-random) process when the system exhausts memory. Is it possible >> this is happening? If so, you should see some log message in one of >> your system logs. >

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
On Tue, 11 Mar 2014 13:58:17 -0700, Ethan Furman wrote: > class Test_wfbrp_20140225(TestCase): > > @classmethod > def setUpClass(cls): > cls.pp = wfbrp.PaymentProcessor( > '.../lockbox_file', > '.../aging_file', > [ > Path

Re: unittest weirdness

2014-03-12 Thread Steven D'Aprano
On Wed, 12 Mar 2014 08:32:29 -0700, Ethan Furman wrote: > There must > be waaay too much stuff being kept alive by the stack traces of the > failed tests. I believe that unittest does keep stack traces alive until the process ends. I thought that there was a recent bug report for it, but th

Re: unittest weirdness

2014-03-12 Thread Roy Smith
In article , Ethan Furman wrote: > > Alternatively, maybe something inside your process is just calling > > sys.exit(), or even os._exit(). You'll see the exit() system call in > > the strace output. > > My bare try/except would have caught that. A bare except would catch sys.exit(), but not

Re: unittest weirdness

2014-03-12 Thread Ethan Furman
On 03/12/2014 06:44 AM, Roy Smith wrote: In article , Ethan Furman wrote: I've tried it both ways, and both ways my process is being killed, presumably by the O/S. What evidence do you have the OS is killing the process? I put a bare try/except around the call to unittest.main, with a pr

Re: unittest weirdness

2014-03-12 Thread Roy Smith
In article , Ethan Furman wrote: > I've tried it both ways, and both ways my process is being killed, presumably > by the O/S. What evidence do you have the OS is killing the process? Some systems have an oom (Out Of Memory) process killer, which nukes (semi-random) process when the system e

Re: unittest weirdness

2014-03-12 Thread Ethan Furman
On 03/11/2014 08:36 PM, Terry Reedy wrote: On 3/11/2014 6:13 PM, John Gordon wrote: In Ethan Furman writes: if missing: raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (

Re: unittest weirdness

2014-03-11 Thread Terry Reedy
On 3/11/2014 6:13 PM, John Gordon wrote: In Ethan Furman writes: if missing: raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of ra

Re: unittest weirdness

2014-03-11 Thread Ethan Furman
On 03/11/2014 03:13 PM, John Gordon wrote: Ethan Furman writes: if missing: raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of raisin

Re: unittest weirdness

2014-03-11 Thread Ethan Furman
On 03/11/2014 01:58 PM, Ethan Furman wrote: Anybody have any ideas? I suspect the O/S is killing the process. If I manually select the other class to run (which has all successful tests, so no traceback baggage), it runs normally. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/pyth

Re: unittest weirdness

2014-03-11 Thread John Gordon
In Ethan Furman writes: > if missing: > raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of raising exceptions. Perhaps that's the issue?

Re: Unittest fails to import module

2013-06-29 Thread Martin Schöön
On 2013-06-29, Steven D'Aprano wrote: > On Sat, 29 Jun 2013 19:13:47 +, Martin Schöön wrote: > >> $PYTHONPATH points at both the code and the test directories. >> >> When I run blablabla_test.py it fails to import blablabla.py > > What error message do you get? > > >> I have messed around f

Re: Unittest fails to import module

2013-06-29 Thread Steven D'Aprano
On Sat, 29 Jun 2013 19:13:47 +, Martin Schöön wrote: > $PYTHONPATH points at both the code and the test directories. > > When I run blablabla_test.py it fails to import blablabla.py What error message do you get? > I have messed around for oven an hour and get nowhere. I have done > unitt

Re: Unittest fails to import module

2013-06-29 Thread Roy Smith
In article , Martin Schöön wrote: > I know the answer to this must be trivial but I am stuck... > > I am starting on a not too complex Python project. Right now the > project file structure contains three subdirectories and two > files with Python code: > > code >blablabla.py > test >b

Re: unittest for system testing

2012-10-18 Thread Steven D'Aprano
Sorry for breaking threading, but the original post has not come through to me. > On 18/10/2012 01:22, Rita wrote: > Hi, > > Currently, I use a shell script to test how my system behaves before I > deploy an application. For instance, I check if fileA, fileB, and fileC > exist and if they do I go

Re: unittest for system testing

2012-10-17 Thread Dave Angel
On 10/17/2012 08:22 PM, Rita wrote: > Hi, > > Currently, I use a shell script to test how my system behaves before I > deploy an application. For instance, I check if fileA, fileB, and fileC > exist and if they do I go and start up my application. > > This works great BUT > > I would like to use py

Re: unittest for system testing

2012-10-17 Thread Rita
thanks. I suppose I would need a simple example from one of these libraries. ( i typed too soon for , "no code needed" ) On Wed, Oct 17, 2012 at 8:49 PM, Mark Lawrence wrote: > On 18/10/2012 01:22, Rita wrote: > >> Hi, >> >> Currently, I use a shell script to test how my system behaves before

Re: unittest for system testing

2012-10-17 Thread Mark Lawrence
On 18/10/2012 01:22, Rita wrote: Hi, Currently, I use a shell script to test how my system behaves before I deploy an application. For instance, I check if fileA, fileB, and fileC exist and if they do I go and start up my application. This works great BUT I would like to use python and in part

Re: Unittest - testing for filenames and filesize

2012-08-31 Thread 88888 Dihedral
On Saturday, September 1, 2012 12:19:10 AM UTC+8, Chris Withers wrote: > On 23/08/2012 12:25, Tigerstyle wrote: > > > class FileTest(unittest.TestCase): > > > > > > def setUp(self): > > > self.origdir = os.getcwd() > > > self.dirname = tempfile.mkdtemp("testdir") > > >

Re: Unittest - testing for filenames and filesize

2012-08-31 Thread Chris Withers
On 23/08/2012 12:25, Tigerstyle wrote: class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) I wouldn't change directories like this, it's pretty fragile, just use absolu

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Tigerstyle
Ahh, thank you very much Rob. Fixed now. Have a great day. T kl. 19:51:54 UTC+2 søndag 26. august 2012 skrev Rob Day følgende: > On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > > > self.assertEqual(statinfo.st_size, filesize) > > > > > > I'm still getting AssertionEr

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Rob Day
On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > self.assertEqual(statinfo.st_size, filesize) > > I'm still getting AssertionError and the error says: 100 !=b' > > filesize is the character 'b' repeated one million times (the contents of the file, in other words). statinfo

Re: Unittest - testing for filenames and filesize

2012-08-26 Thread Tigerstyle
Thanks Rob, I'v modified the test_3 like this: def test_3(self): f = open("test.dat", "wb") filesize = (b'b'*100) f.write(filesize) f.close() statinfo = os.stat("test.dat") self.assertEqual(statinfo.st_size, filesize) I'm still getting

Re: Unittest - testing for filenames and filesize

2012-08-24 Thread Robert Day
On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote: > def test_3(self): > f = open("test.dat", "wb") > filesize = b"0"*100 > f.write(filesize) > f.close() > self.assertEqual(os.stat, filesize) > The test_3 is to test if the created binary file har

Re: Unittest - testing for filenames and filesize

2012-08-24 Thread Tigerstyle
Thank you guys, Roy and Terry. I has been great help. I still need some help. Here is the updated code: Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Roy Smith
On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > One can start with a set rather than tuple of file names. > filenames = {"this.txt", "that.txt", "the_other.txt"} Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or abo

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Terry Reedy
On 8/23/2012 8:28 AM, Roy Smith wrote: I think you want to end up with something like: def test_1(self): "Verify creation of files is possible" filenames = ("this.txt", "that.txt", "the_other.txt") for filename in filenames: f = open(filename, "w")

Re: Unittest - testing for filenames and filesize

2012-08-23 Thread Roy Smith
In article <6b0299df-bc24-406b-8d69-489e990d8...@googlegroups.com>, Tigerstyle wrote: > Hi. > > I need help with an assignment and I hope you guys can guide me in the right > direction. > [code elided] > 1. The test_1() method includes code to verify that the test directory > contains only th

Re: unittest - sort cases to be run

2012-08-21 Thread Peter Otten
Kevin Zhang wrote: > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "Note that the order in which the various test cases will be run is > determined by sorting the test function names with respect to the built-in > ordering for strings." > >

Re: unittest - sort cases to be run

2012-08-21 Thread goon12
On Tuesday, August 21, 2012 5:34:33 AM UTC-4, Terry Reedy wrote: > On 8/21/2012 5:09 AM, Kevin Zhang wrote: > > > Hi all, > > > > > > I want to sort the order of the unittest cases to be run, but found such > > > statement in Python doc, > > > "Note that the order in which the various test cas

Re: unittest - sort cases to be run

2012-08-21 Thread Terry Reedy
On 8/21/2012 5:09 AM, Kevin Zhang wrote: Hi all, I want to sort the order of the unittest cases to be run, but found such statement in Python doc, "Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in orderi

Re: unittest: Improve discoverability of discover (Was: Initial nose experience)

2012-07-16 Thread Philipp Hagemeister
On 07/16/2012 02:37 PM, Philipp Hagemeister wrote: > Can we improve the discoverability of the discover > option, for example by making it the default action, or including a > message "use discover to find test files automatically" if there are no > arguments? Oops, already implemented as of Python

Re: unittest: assertRaises() with an instance instead of a type

2012-04-02 Thread Steve Howell
On Mar 28, 6:55 pm, Ben Finney wrote: > Steven D'Aprano writes: > > (By the way, I have to question the design of an exception with error > > codes. That seems pretty poor design to me. Normally the exception *type* > > acts as equivalent to an error code.) > > Have a look at Python's built-in OS

Re: unittest: assertRaises() with an instance instead of a type

2012-03-30 Thread Ethan Furman
Steven D'Aprano wrote: To the degree that the decision of how finely to slice tests is a matter of personal judgement and/or taste, I was wrong to say "that is not the right way". I should have said "that is not how I would do that test". I believe that a single test is too coarse, and three o

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Steven D'Aprano
On Thu, 29 Mar 2012 08:35:16 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: >> >>> Hi! >>> >>> I'm currently writing some tests for the error handling of some code. >>> In this scenario, I must make sure that both the correct exce

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Steven D'Aprano
On Thu, 29 Mar 2012 09:08:30 +0200, Ulrich Eckhardt wrote: > Am 28.03.2012 20:07, schrieb Steven D'Aprano: >> Secondly, that is not the right way to do this unit test. You are >> testing two distinct things, so you should write it as two separate >> tests: > [..code..] >> If foo does *not* raise a

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Ethan Furman
Steven D'Aprano wrote: On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: Hi! I'm currently writing some tests for the error handling of some code. In this scenario, I must make sure that both the correct exception is raised and that the contained error code is correct: try:

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Terry Reedy
On 3/29/2012 3:28 AM, Ulrich Eckhardt wrote: Equality comparison is by id. So this code will not do what you want. >>> Exception('foo') == Exception('foo') False Yikes! That was unexpected and completely changes my idea. Any clue whether this is intentional? Is identity the fallback when no

Re: tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type)

2012-03-29 Thread Roy Smith
In article <0ved49-hie@satorlaser.homedns.org>, Ulrich Eckhardt wrote: > I didn't consciously use tabs, actually I would rather avoid them. That > said, my posting looks correctly indented in my "sent" folder and also > in the copy received from my newsserver. What could also have an > in

tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type)

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:26, schrieb Terry Reedy: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: [...] # call testee and verify results try: ...call function here... except exception_type as e: if not exception is None: self.assertEqual(e, exception) Did you use tabs? They do not get preserved indefini

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:26, schrieb Terry Reedy: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: with self.assertRaises(MyException(SOME_FOO_ERROR)): foo() I presume that if this worked the way you want, all attributes would have to match. The message part of builtin exceptions is allowed to change,

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Peter Otten
Ulrich Eckhardt wrote: > True. Normally. I'd adapting to a legacy system though, similar to > OSError, and that system simply emits error codes which the easiest way > to handle is by wrapping them. If you have err = some_func() if err: raise MyException(err) the effort to convert it to e

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Ulrich Eckhardt
Am 28.03.2012 20:07, schrieb Steven D'Aprano: First off, that is not Python code. "catch Exception" gives a syntax error. Old C++ habits... :| Secondly, that is not the right way to do this unit test. You are testing two distinct things, so you should write it as two separate tests: [..code

Re: unittest: assertRaises() with an instance instead of a type

2012-03-29 Thread Peter Otten
Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception *type* >> acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various

Re: unittest: assertRaises() with an instance instead of a type

2012-03-28 Thread Steven D'Aprano
On Thu, 29 Mar 2012 12:55:13 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception >> *type* acts as equivalent to an error code.) > > Have a look at Pyt

Re: unittest: assertRaises() with an instance instead of a type

2012-03-28 Thread Ben Finney
Steven D'Aprano writes: > (By the way, I have to question the design of an exception with error > codes. That seems pretty poor design to me. Normally the exception *type* > acts as equivalent to an error code.) Have a look at Python's built-in OSError. The various errors from the operating sy

Re: unittest: assertRaises() with an instance instead of a type

2012-03-28 Thread Terry Reedy
On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: Hi! I'm currently writing some tests for the error handling of some code. In this scenario, I must make sure that both the correct exception is raised and that the contained error code is correct: try: foo() self.fail('exception not raised') catch M

Re: unittest: assertRaises() with an instance instead of a type

2012-03-28 Thread Steven D'Aprano
On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: > Hi! > > I'm currently writing some tests for the error handling of some code. In > this scenario, I must make sure that both the correct exception is > raised and that the contained error code is correct: > > >try: >foo()

Re: unittest and threading

2012-01-25 Thread Mark Hammond
Let me have a guess :) On 25/01/2012 7:42 PM, Ross Boylan wrote: On Tue, 2012-01-24 at 13:54 -0800, Ross Boylan wrote: ... The code I want to test uses threads, but that is not entirely internal from the standpoint of the unit test framework. The unit test will be executing in one thread, but

Re: unittest and threading

2012-01-25 Thread Ross Boylan
On Tue, 2012-01-24 at 13:54 -0800, Ross Boylan wrote: > Is it safe to use unittest with threads? > > In particular, if a unit test fails in some thread other than the one > that launched the test, will that information be captured properly? > > A search of the net shows a suggestion that all fail

Re: unittest and threading

2012-01-24 Thread Steven D'Aprano
On Tue, 24 Jan 2012 13:54:23 -0800, Ross Boylan wrote: > Is it safe to use unittest with threads? I see nobody else has answered, so I'll have a go. I think you need to explain what you mean here in a little more detail. If you mean, "I have a library that uses threads internally, and I want t

Re: unittest. customizing tstloaders / discover()

2011-12-12 Thread Nathan Rice
Nose is absolutely the way to go for your testing needs. You can put "__test__ = False" in modules or classes to stop test collection. On Mon, Dec 12, 2011 at 5:44 AM, Thomas Bach wrote: > Gelonida N writes: > >> Do I loose anything if using nose. or example can all unit tests / doc >> tests st

Re: unittest. customizing tstloaders / discover()

2011-12-12 Thread Thomas Bach
Gelonida N writes: > Do I loose anything if using nose. or example can all unit tests / doc > tests still be run from nose? AFAIK you don't loose anything by using nose – the unittests should all be found and doctests can be run via `--with-doctest', I never used doctests though. regards -- ht

Re: unittest. customizing tstloaders / discover()

2011-12-11 Thread Gelonida N
On 12/12/2011 12:27 AM, Thomas Bach wrote: > Gelonida N writes: > >> I'd like to use regular expresions as include / exclude rules >> and I would like to have another filter function, which would check for >> the existence of certain metavariabels in test suite files > > Did you have a look at n

Re: unittest. customizing tstloaders / discover()

2011-12-11 Thread Thomas Bach
Gelonida N writes: > I'd like to use regular expresions as include / exclude rules > and I would like to have another filter function, which would check for > the existence of certain metavariabels in test suite files Did you have a look at nose? I'm using it and it supports include/exclude rule

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Roy Smith
In article , Tim Chase wrote: > On 09/28/11 19:52, Roy Smith wrote: > > In many cases, there's only two states of interest: > > > > 1) All tests pass > > > > 2) Anything else > > Whether for better or worse, at some places (such as a previous > employer) the number (and accretion) of test-poin

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Tim Chase
On 09/28/11 19:52, Roy Smith wrote: In many cases, there's only two states of interest: 1) All tests pass 2) Anything else Whether for better or worse, at some places (such as a previous employer) the number (and accretion) of test-points is a marketing bullet-point for upgrades & new relea

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Roy Smith
In article <874nzw3wxc@benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > In article <87k48szqo1@benfinney.id.au>, > > Ben Finney wrote: > > > > > Worse, if one of the scenarios causes the test to fail, the loop will > > > end and you won't get the results for the remainin

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Ben Finney
Steven D'Aprano writes: > I used to ask the same question, but then I decided that if I wanted > each data point to get its own tick, I should bite the bullet and > write an individual test for each. Hence my advocating the ‘testscenarios’ library. Have you tried that? It allows the best of bot

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Ben Finney
Roy Smith writes: > In article <87k48szqo1@benfinney.id.au>, > Ben Finney wrote: > > > Worse, if one of the scenarios causes the test to fail, the loop will > > end and you won't get the results for the remaining scenarios. > > Which, depending on what you're doing, may or may not be import

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Eric Snow
On Wed, Sep 28, 2011 at 6:50 PM, Devin Jeanpierre wrote: >> I used to ask the same question, but then I decided that if I wanted each >> data point to get its own tick, I should bite the bullet and write an >> individual test for each. > > Nearly the entire re module test suite is a list of tuples

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Roy Smith
In article <87k48szqo1@benfinney.id.au>, Ben Finney wrote: > Worse, if one of the scenarios causes the test to fail, the loop will > end and you won't get the results for the remaining scenarios. Which, depending on what you're doing, may or may not be important. In many cases, there's on

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Devin Jeanpierre
> I used to ask the same question, but then I decided that if I wanted each > data point to get its own tick, I should bite the bullet and write an > individual test for each. Nearly the entire re module test suite is a list of tuples. If it was instead a bunch of TestCase classes, there'd be a lo

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Roy Smith
In article <4e83b8e0$0$29972$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > If you are writing loops inside tests, you might find this anecdote useful: > > http://mail.python.org/pipermail/python-list/2011-April/1270640.html On the other hand, the best test is one that gets writ

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Steven D'Aprano
Tim Chase wrote: > While I asked this on the Django list as it happened to be with > some Django testing code, this might be a more generic Python > question so I'll ask here too. > > When performing unittest tests, I have a number of methods of the > form > >def test_foo(self): > data

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Terry Reedy
On 9/28/2011 10:16 AM, Tim Chase wrote: When performing unittest tests, I have a number of methods of the form def test_foo(self): data = ( (item1, result1), ... #bunch of tests for fence-post errors ) for test, result in data: self.assertEqual(process(test), result) When I run my tests, I onl

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Ben Finney
Ben Finney writes: > You can use the third-party ‘testscenarios’ library The URL got a bit mangled. The proper PyPI URL for that library is http://pypi.python.org/pypi/testscenarios>. > to generate test cases at run time, one for each combination of > scenarios with test cases on the class. The

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Ben Finney
Tim Chase writes: > def test_foo(self): > data = ( > (item1, result1), > ... #bunch of tests for fence-post errors > ) > for test, result in data: > self.assertEqual(process(test), result) The sets of data for running the same test we might call “scenarios”. >

Re: Unittest: how to pass information to TestCase classes?

2010-10-26 Thread Steve Holden
On 10/26/2010 2:46 PM, AK wrote: > Hi, I have a question about unittest: let's say I create a temp dir for > my tests, then use loadTestsFromNames() to load my tests from packages > and modules they're in, then use TextTestRunner.run() to run the tests, > how can I pass information to TestCase inst

Re: Unittest: how to pass information to TestCase classes?

2010-10-26 Thread Ben Finney
AK writes: > Hi, I have a question about unittest: let's say I create a temp dir > for my tests, then use loadTestsFromNames() to load my tests from > packages and modules they're in, then use TextTestRunner.run() to run > the tests, how can I pass information to TestCase instances, e.g. the > lo

Re: unittest basics

2010-05-11 Thread Chris Withers
import unittest class MyTestCase(unittest.TestCase): def test_my_import(self): import blah cheers, Chris John Maclean wrote: is there a way to test that a certian library or module is or can be loaded successfully? self.assert('import blah') -- Simplistix - Content Management, Bat

Re: unittest basics

2010-05-11 Thread Giampaolo Rodolà
There's no reason for such a thing. You can just make "import module" in your test and if something goes wrong that will be treated as any other test failure. --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil 2010/5/11 John Maclean : > is there a way to test that a

Re: unittest not being run

2010-05-10 Thread Joe Riopel
On Mon, May 10, 2010 at 5:17 PM, cjw wrote: > PyScripter and PythonWin permit the user to choose the equivalence of tabs > and spaces.  I like two spaces = on tab, it's a matter of taste.  I feel > that eight spaces is too much. While it is a matter of taste, PEP 8 recommends 4 spaces per indent

Re: unittest not being run

2010-05-10 Thread cjw
On 10-May-10 10:21 AM, John Maclean wrote: On 10/05/2010 14:38, J. Cliff Dyer wrote: My guess is you mixed tabs and spaces. One tab is always treated by the python interpreter as being equal to eight spaces, which is two indentation levels in your code. Though if it were exactly as you show it,

Re: unittest not being run

2010-05-10 Thread John Maclean
On 10/05/2010 14:38, J. Cliff Dyer wrote: My guess is you mixed tabs and spaces. One tab is always treated by the python interpreter as being equal to eight spaces, which is two indentation levels in your code. Though if it were exactly as you show it, you'd be getting a syntax error, because e

Re: unittest not being run

2010-05-10 Thread J. Cliff Dyer
My guess is you mixed tabs and spaces. One tab is always treated by the python interpreter as being equal to eight spaces, which is two indentation levels in your code. Though if it were exactly as you show it, you'd be getting a syntax error, because even there, it looks like the indentation of

Re: unittest not being run

2010-05-10 Thread Joe Riopel
On Mon, May 10, 2010 at 8:38 AM, John Maclean wrote: > hi, > > can some one explain why the __first__ test is not being run? It looks like you defined test_T1 inside of the tearDown method. -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest help needed!

2010-01-14 Thread Phlip
Oltmans wrote: def test_first(self): print 'first test' process(123) All test cases use the pattern "Assemble Activate Assert". You are assembling a 123, and activating process(), but where is your assert? If it is inside process() (if process is a test-side method), then

Re: unittest help needed!

2010-01-14 Thread Oltmans
On Jan 14, 11:46 pm, exar...@twistedmatrix.com wrote: > When you run test.py, it gets to the loadTestsFromName line.  There, it > imports the module named "test" in order to load tests from it.  To > import > that module, it runs test.py again.  By the time it finishes running the > contents of t

Re: unittest help needed!

2010-01-14 Thread exarkun
On 06:33 pm, rolf.oltm...@gmail.com wrote: Hi Python gurus, I'm quite new to Python and have a problem. Following code resides in a file named test.py --- import unittest class result(unittest.TestResult): pass class tee(unittest.TestCase): def test_first(self): print 'first te

Re: unittest inconsistent

2010-01-12 Thread Chris Withers
Phlip wrote: The reason the 'Tester' object has no attribute 'arg1' is because "self" still refers to the object made for testA. I hope someone else can spot the low-level reason... ...but why aren't you using http://pypi.python.org/pypi/mock/ ? Look up its patch_object facility... Indeed, I

Re: unittest inconsistent

2010-01-06 Thread Peter Otten
André wrote: > On Jan 5, 8:14 pm, Matt Haggard wrote: >> Can anyone tell me why this test fails? >> >> http://pastebin.com/f20039b17 >> >> This is a minimal example of a much more complex thing I'm trying to >> do. I'm trying to hijack a function and inspect the args passed to it >> by another f

Re: unittest inconsistent

2010-01-05 Thread André
On Jan 5, 8:14 pm, Matt Haggard wrote: > Can anyone tell me why this test fails? > > http://pastebin.com/f20039b17 > > This is a minimal example of a much more complex thing I'm trying to > do.  I'm trying to hijack a function and inspect the args passed to it > by another function. > > The reason

Re: unittest inconsistent

2010-01-05 Thread Phlip
On Jan 5, 4:14 pm, Matt Haggard wrote: > Can anyone tell me why this test fails? > > http://pastebin.com/f20039b17 > > This is a minimal example of a much more complex thing I'm trying to > do.  I'm trying to hijack a function and inspect the args passed to it > by another function. > > The reason

Re: unittest buffing output on windows?

2009-12-07 Thread Dave Angel
Roy Smith wrote: I'm running 2.5.1. I've got a test suite that takes about 15 minutes to complete. On my unix boxes, as each test case executes, it prints out a line (I'm using unittest.TextTestRunner(verbosity=2)) of status, but on my windows box (running under cygwin), it buffers everything u

Re: unittest & setup

2009-11-04 Thread Joe Riopel
On Tue, Nov 3, 2009 at 11:02 PM, Jonathan Haddad wrote: > I've got a class, in the constructor it loads a CSV file from disc.  I'd > like only 1 instance of the class to be instantiated.  However, when running > multiple unit tests, multiple instances of the class are created.  What's > the best w

Re: unittest & setup

2009-11-03 Thread Gabriel Genellina
En Wed, 04 Nov 2009 01:02:24 -0300, Jonathan Haddad escribió: I've got a class, in the constructor it loads a CSV file from disc. I'd like only 1 instance of the class to be instantiated. However, when running multiple unit tests, multiple instances of the class are created. What's the

Re: unittest wart/bug for assertNotEqual

2009-10-22 Thread Ethan Furman
Gabriel Genellina wrote: En Tue, 20 Oct 2009 19:57:19 -0300, Ethan Furman escribió: Steven D'Aprano wrote: On Tue, 20 Oct 2009 14:45:49 -0700, Zac Burns wrote: My preference would be that failIfEqual checks both != and ==. This is practical, and would benefit almost all use cases. If "!="

Re: unittest wart/bug for assertNotEqual

2009-10-22 Thread Gabriel Genellina
En Tue, 20 Oct 2009 19:57:19 -0300, Ethan Furman escribió: Steven D'Aprano wrote: On Tue, 20 Oct 2009 14:45:49 -0700, Zac Burns wrote: My preference would be that failIfEqual checks both != and ==. This is practical, and would benefit almost all use cases. If "!=" isn't "not ==" (IEEE NaNs

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Ethan Furman
Steven D'Aprano wrote: On Tue, 20 Oct 2009 14:45:49 -0700, Zac Burns wrote: My preference would be that failIfEqual checks both != and ==. This is practical, and would benefit almost all use cases. If "!=" isn't "not ==" (IEEE NaNs I hear is the only known use case) numpy uses == and != as

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Steven D'Aprano
On Tue, 20 Oct 2009 14:45:49 -0700, Zac Burns wrote: > My preference would be that failIfEqual checks both != and ==. This is > practical, and would benefit almost all use cases. If "!=" isn't "not > ==" (IEEE NaNs I hear is the only known use case) numpy uses == and != as element-wise operators:

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Zac Burns
> I was with you right up to the last six words. > > Whether it's worth changing assertNotEqual to be something other than an > alias of failIfEqual is an interesting question. Currently all the > assert* and fail* variants are aliases of each other, which is easy to > learn. This would introduce a

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Steven D'Aprano
On Tue, 20 Oct 2009 10:20:54 -0700, Zac Burns wrote: > Using the assertNotEqual method of UnitTest (synonym for failIfEqual) > only checks if first == second, but does not include not (first != > second) > > According to the docs: > http://docs.python.org/reference/datamodel.html#specialnames The

  1   2   3   >