[Twisted-Python] Get trial to use the docstring?
Is there already a way to get twisted to print out a test's docstring (like unittest does) instead of the name of the function in it's output? I've looked at trial's options and searched the list archives, but I'm not seeing anything... For example, here's what my tests look like when run by unittest: $ test/run.py -v ==> Starting Prerequisite Tests ... ok Supported OS? ... ok Supported version of Python? ... ok ... And here's what they look like when run by trial: $ trial test/run.py run Test00Prerequisites test_00banner ... [OK] test_01os ... [OK] ... ~ Nathan
On Aug 5, 2010, at 2:33 PM, Nathan wrote:
Is there already a way to get twisted to print out a test's docstring (like unittest does) instead of the name of the function in it's output? I've looked at trial's options and searched the list archives, but I'm not seeing anything...
For example, here's what my tests look like when run by unittest:
$ test/run.py -v ==> Starting Prerequisite Tests ... ok Supported OS? ... ok Supported version of Python? ... ok ...
And here's what they look like when run by trial:
$ trial test/run.py run Test00Prerequisites test_00banner ... [OK] test_01os ... [OK] ...
No. If you want to add a feature that prints out the docstring (or some portion of it) _in addition_ to the test name, that would probably be accepted as a patch. But, in my mind, one of the most important features of trial is the fact that it prints out stable identifiers for the tests so you can see how to run them again when you're looking at their results. We should never omit that. (In fact, I'd really like it if trial always printed out a _full_ test identifier for easy copy/pasting instead of sometimes only printing the method name.)
On 07:08 pm, glyph@twistedmatrix.com wrote:
On Aug 5, 2010, at 2:33 PM, Nathan wrote:
Is there already a way to get twisted to print out a test's docstring (like unittest does) instead of the name of the function in it's output? I've looked at trial's options and searched the list archives, but I'm not seeing anything...
For example, here's what my tests look like when run by unittest:
$ test/run.py -v ==> Starting Prerequisite Tests ... ok Supported OS? ... ok Supported version of Python? ... ok ...
And here's what they look like when run by trial:
$ trial test/run.py run Test00Prerequisites test_00banner ... [OK] test_01os ... [OK] ...
No.
If you want to add a feature that prints out the docstring (or some portion of it) _in addition_ to the test name, that would probably be accepted as a patch. But, in my mind, one of the most important features of trial is the fact that it prints out stable identifiers for the tests so you can see how to run them again when you're looking at their results. We should never omit that. (In fact, I'd really like it if trial always printed out a _full_ test identifier for easy copy/pasting instead of sometimes only printing the method name.)
Also, trial reporters are pluggable, so you can always write and use a reporter that prints out exactly what you want printed out. Jean-Paul
On Thu, Aug 5, 2010 at 1:49 PM, <exarkun@twistedmatrix.com> wrote:
If you want to add a feature that prints out the docstring (or some portion of it) _in addition_ to the test name, that would probably be accepted as a patch. But, in my mind, one of the most important features of trial is the fact that it prints out stable identifiers for the tests so you can see how to run them again when you're looking at their results. We should never omit that. (In fact, I'd really like it if trial always printed out a _full_ test identifier for easy copy/pasting instead of sometimes only printing the method name.)
Also, trial reporters are pluggable, so you can always write and use a reporter that prints out exactly what you want printed out.
Jean-Paul
I have a number of questions: 1) I found the TreeReporter class that produces the default output (twisted/trial/reporter.py), and I found the file that seems to get run by trial (twisted/scripts/trial.py) but for the life of me I couldn't figure out how to get my own class to show up as one of the reporters that you can select by means of the --reporter=whatever argument. How do you tie the two together? I can just submit my modified TreeReporter, but it'd be nice to be able to also submit a wildly different option... 2) What's the official process for submitting a patch (or where is the process documented)? I've never actually contributed code to twisted... 3) Every time I install my custom twisted (with "sudo python setup.py install" on OS X 10.6.4 system python), trial starts spitting out the "dropin cache" error (see [1] below) which persists until I run "sudo twistd --help" as was suggested on the list last week or so. Isn't there some way we can just address that error condition at installation time so that doesn't occur in the first place? 4) I'm sold on test-driven development (which is why I'm learning trial), so I'd like to both check for regressions and write a test for my patch. I found twisted/trial/test/test_reporter.py -- how do I run just the tests in that file? Does trial run on itself? ~ Nathan [1] Traceback (most recent call last): File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/python/usage.py", line 241, in parseOptions self.postOptions() File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/scripts/trial.py", line 295, in postOptions self['reporter'] = self._loadReporterByName(self['reporter']) File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/scripts/trial.py", line 281, in _loadReporterByName for p in plugin.getPlugins(itrial.IReporter): File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/plugin.py", line 199, in getPlugins allDropins = getCache(package) --- <exception caught here> --- File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/plugin.py", line 178, in getCache dropinPath.setContent(pickle.dumps(dropinDotCache)) File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/python/filepath.py", line 765, in setContent f = sib.open('w') File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/python/filepath.py", line 515, in open return self.create() File "/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/python/filepath.py", line 791, in create fdint = os.open(self.path, _CREATE_FLAGS) exceptions.OSError: [Errno 13] Permission denied: '/Library/Python/2.6/site-packages/Twisted-10.1.0_r29921-py2.6-macosx-10.6-universal.egg/twisted/plugins/bDcpsOvnXomi7b94dropin.cache.new'
On 8/5/10 6:25 PM, Nathan wrote:
I have a number of questions:
1) I found the TreeReporter class that produces the default output (twisted/trial/reporter.py), and I found the file that seems to get run by trial (twisted/scripts/trial.py) but for the life of me I couldn't figure out how to get my own class to show up as one of the reporters that you can select by means of the --reporter=whatever argument. How do you tie the two together? I can just submit my modified TreeReporter, but it'd be nice to be able to also submit a wildly different option...
Wildly different options sound like a good case for plugins: http://twistedmatrix.com/documents/current/core/howto/plugin.html You need to create a plugin that makes your reporter accessible to Trial. This means it needs to implement the IReporter interface: http://twistedmatrix.com/documents/10.1.0/api/twisted.trial.itrial.IReporter... The plugin should be installed on your PYTHONPATH in a directory named twisted/plugins. You could just place this in your project for instance, or in the system twisted/plugins dir. myproject/twisted/plugins/awesome_reporter.py The plugin describes the reporter (for --help-reporters) and provides the importable module and class that gets instantiated. The reporter itself can be a subclass of TreeReporter or whatever, and should implement the IReporter interface. Here is a simple example: http://gist.github.com/510688 For a much better example, check out the Tahoe-LAFS project trialcoverage reporter: http://tahoe-lafs.org/source/trialcoverage/trunk/
2) What's the official process for submitting a patch (or where is the process documented)? I've never actually contributed code to twisted...
Start here: http://twistedmatrix.com/trac/wiki/ContributingToTwistedLabs
3) Every time I install my custom twisted (with "sudo python setup.py install" on OS X 10.6.4 system python), trial starts spitting out the "dropin cache" error (see [1] below) which persists until I run "sudo twistd --help" as was suggested on the list last week or so. Isn't there some way we can just address that error condition at installation time so that doesn't occur in the first place?
"Some way" always comes down to "Someone", which I suspect is a bit like that ghost the kid from Family Circus is always blaming for muddy footprints or whatever counts for domestic drama in Bil Keane's Geritol-addled imagination. So....there's an existing ticket you could help out with: http://twistedmatrix.com/trac/ticket/2409
4) I'm sold on test-driven development (which is why I'm learning trial), so I'd like to both check for regressions and write a test for my patch. I found twisted/trial/test/test_reporter.py -- how do I run just the tests in that file? Does trial run on itself?
Yes. Trial is pretty flexible about specifying tests to run, so you can run the whole suite, specify a directory of tests, or point it to a specific TestCase: trial twisted trial twisted/test trial twisted.test trial twisted/trial/test/test_reporter.py trial twisted.trial.test.test_reporter.TestTreeReporter The same holds for your own project: trial myproject.tests.test_reporter.AwesomeTreeReporter
participants (4)
-
exarkun@twistedmatrix.com
-
Glyph Lefkowitz
-
Lucas Taylor
-
Nathan