I was taking a look at this and I have a few thoughts:
There will be necessary to change the current test loading method (loadTestsFromTestCase) since it needs a valid class to run, and a method will not satisfy that.
The test loading method I suggest is loadTestsFromName (doc) which needs a string pointing to what we want to test, and that will be perfect for testing single methods.
With this approach it won't be necessary to dynamically load modules with !import!, since that is handled by loadTestsFromName itself ;)
I've implemented all of the above and I'll reply with the suggested code ASAP!
I basically changed from loadTestsFromTestCase to loadTestsFromName, added a try-except on run_tests and modified _get_tests in util.py in order to:
Look for the given string (module_substring) in modules list.
If nothing found, remove last fragment of the string (what is supposed to be a method) and try again. If something is found after that, it will return the module found + the name of the method.
To test the changes I made, I tried with the following arguments:
--all
--all --test test.integ.process (process module)
--all --test process
--integ --test test.integ.process
--integ --test process
--all --test test.integ.process.test_quiet_argument (process module + single method)
--integ --test process.test_quiet_arguments ('s' at the end, non existing method)
This will show nothing (as it does now)
--integ --test processs (triple 's' at the end, non existing module)
Finally, there is one thing I haven't been able to solve: testing a non existing module inside a sub folder. For example:
--all --test test.integ.descriptor.microdescriptors (extra 's' at the end, non existing module)
As this module is not found, the program will remove the last fragment (microdescriptors) and try to look for test.integ.descriptor, which is the base for 5 sub modules that do exist, and will find all of them and try for the "method" microdescriptors on them, which will finally produce 5 "failed messages". The problem here is that tere is no way of knowing beforehand if the given string corresponds to a submodule or a method... so I've been thinking that there are two possible solutions for this:
List all method names in settings.cfg, as it is done now for module names.
Add a new argument for testing single methods, so we know beforehand that we were asked for that and not something else. It could be something like --test-method
Hi civ, gonna reopen this. Minor issue I just noticed is that when tests have errors we report 'no such test' rather than a failure. For instance, try making a syntax error in a test module and run it.
This isn't a terribly big whoop (pyflakes catches these too) but probably a regression we should fix. :P
Trac: Status: closed to reopened Resolution: implemented toN/A