[Twisted-Python] Some way for Trial to allow selective running of tests?

I've been successfully and happily using Trial for a while now for development of a server. I have many tests at this point; during development of a new feature, I'd like to have a convenient way to only run the tests relevant to that feature. I'm hacking it at this point by prefixing the names of all unwanted tests with "foo" to keep them from being recognized. Naturally, I'd like a better way to do this. Any good words welcome. -- Don Dwiggins Advanced Publishing Technology

On Aug 27, 2009, at 4:00 PM, Don Dwiggins wrote:
trial takes an argument at the command-line where you can specify a package or test case. for example: trial twisted trial twisted.test trial twisted.test.test_explorer trial twisted.test.test_explorer.TestBrowser trial twisted.test.test_explorer.TestBrowser.test_chain lets you get more and more specific. -phil

Phil Christensen wrote:
Sorry, I'm feeling dense. I currently run it as "trial MyServerTestFile.py"; it's not a package or part of one. In the file are several classes, each with several test cases. How would I adapt the above to my needs? -- Don Dwiggins Advanced Publishing Technology

Don Dwiggins <ddwiggins@advpubtech.com> wrote:
trial takes either a path and filename, or a Python import name (I'm not sure what the exact term here is). If you ran python in the same directory where you ran "trial" in your example, you could say: import MyServerTestFile MyServerTestFile.MyServerTestCase.test_my_server ...to refer to a particular test method, and trial will accept the same syntax: trial MyServerTestFile.MyServerTestCase.test_my_server In general though, a lot of distribution and packaging and deployment things become easier if your project is laid out in Python packages. I usually follow these rules and everything turns out pretty well: http://jcalderone.livejournal.com/39794.html

Tim Allen wrote:
That's progress; thanks! It gives me a choice of running either all tests in a particular class, or one test. I could probably cobble up a shell or python script to wrap around it and allow me to run a list of "specs"; it'll be better than all the "foo"ing I've been doing. 8^) A quick thought: maybe I could use decorators on test methods to apply "tags" to my tests, then write a script to run all tests with a given tag; this might be even handier.
Good advice, if you're distributing a python library. In my case, the end result is an installer that creates a single .exe (a Windows service; frozen with py2exe) and a config.ini file. For me, there's no particular value in creating a package hierarchy just for testing. (With one possible exception: I may want to create a multi-level hierarchy of tests, rather than just the fixed file/class/method structure that unittest/trial gives you. -- Don Dwiggins Advanced Publishing Technology

We are using twisted.enterprise.adbapi for connecting to MySQL. In one of our large tables, the primary key reached its maximum value of 2147483647, and INSERTs became impossible. When I executed the same INSERT from mysql command line manually, it gave: ERROR 1062 (23000): Duplicate entry '2147483647' for key 1 In twisted logs however, for the same INSERT the error was much less specific: 2014, "Commands out of sync; you can't run this command now" I am concerned about this, since this 2014 error has appeared before in the twisted logs, in many completely different contexts. Can you shed any light on why we do not get the specific 1062 error, and what this 2014, "Commands out of sync; you can't run this command now" is about?

On Aug 27, 2009, at 4:08 PM, Phil Christensen wrote:
Right, but, far as I can tell, you can only do one at a time. I just want to run the list of ones I know are working even though there are many more written and waiting to be pulled in and debugged (one at a time). IOW, I want to specify a list of tests to run out of many that match the file pattern. S

On Aug 27, 2009, at 4:00 PM, Don Dwiggins wrote:
I was just running into this yesterday and had actually pulled the code for the one thing I use trial for ( the emacs line @ the top of the file to specify unit tests) out to make a nose plug-in since nose allows lists of tests to be put into config files. I'd love to have another way as I will need Trial for the Twisted part of my code later. Thanks, S

On Aug 27, 2009, at 4:00 PM, Don Dwiggins wrote:
trial takes an argument at the command-line where you can specify a package or test case. for example: trial twisted trial twisted.test trial twisted.test.test_explorer trial twisted.test.test_explorer.TestBrowser trial twisted.test.test_explorer.TestBrowser.test_chain lets you get more and more specific. -phil

Phil Christensen wrote:
Sorry, I'm feeling dense. I currently run it as "trial MyServerTestFile.py"; it's not a package or part of one. In the file are several classes, each with several test cases. How would I adapt the above to my needs? -- Don Dwiggins Advanced Publishing Technology

Don Dwiggins <ddwiggins@advpubtech.com> wrote:
trial takes either a path and filename, or a Python import name (I'm not sure what the exact term here is). If you ran python in the same directory where you ran "trial" in your example, you could say: import MyServerTestFile MyServerTestFile.MyServerTestCase.test_my_server ...to refer to a particular test method, and trial will accept the same syntax: trial MyServerTestFile.MyServerTestCase.test_my_server In general though, a lot of distribution and packaging and deployment things become easier if your project is laid out in Python packages. I usually follow these rules and everything turns out pretty well: http://jcalderone.livejournal.com/39794.html

Tim Allen wrote:
That's progress; thanks! It gives me a choice of running either all tests in a particular class, or one test. I could probably cobble up a shell or python script to wrap around it and allow me to run a list of "specs"; it'll be better than all the "foo"ing I've been doing. 8^) A quick thought: maybe I could use decorators on test methods to apply "tags" to my tests, then write a script to run all tests with a given tag; this might be even handier.
Good advice, if you're distributing a python library. In my case, the end result is an installer that creates a single .exe (a Windows service; frozen with py2exe) and a config.ini file. For me, there's no particular value in creating a package hierarchy just for testing. (With one possible exception: I may want to create a multi-level hierarchy of tests, rather than just the fixed file/class/method structure that unittest/trial gives you. -- Don Dwiggins Advanced Publishing Technology

We are using twisted.enterprise.adbapi for connecting to MySQL. In one of our large tables, the primary key reached its maximum value of 2147483647, and INSERTs became impossible. When I executed the same INSERT from mysql command line manually, it gave: ERROR 1062 (23000): Duplicate entry '2147483647' for key 1 In twisted logs however, for the same INSERT the error was much less specific: 2014, "Commands out of sync; you can't run this command now" I am concerned about this, since this 2014 error has appeared before in the twisted logs, in many completely different contexts. Can you shed any light on why we do not get the specific 1062 error, and what this 2014, "Commands out of sync; you can't run this command now" is about?

On Aug 27, 2009, at 4:08 PM, Phil Christensen wrote:
Right, but, far as I can tell, you can only do one at a time. I just want to run the list of ones I know are working even though there are many more written and waiting to be pulled in and debugged (one at a time). IOW, I want to specify a list of tests to run out of many that match the file pattern. S

On Aug 27, 2009, at 4:00 PM, Don Dwiggins wrote:
I was just running into this yesterday and had actually pulled the code for the one thing I use trial for ( the emacs line @ the top of the file to specify unit tests) out to make a nose plug-in since nose allows lists of tests to be put into config files. I'd love to have another way as I will need Trial for the Twisted part of my code later. Thanks, S
participants (5)
-
Alec Matusis
-
Don Dwiggins
-
Phil Christensen
-
Steve Steiner (listsin)
-
Tim Allen