Closed althonos closed 7 years ago
NB: Don't merge right now, I have some strange issues on some tests I'm not sure how to reproduce, where ProtoTest
objects exit the queue in runner.run
.
Wow! You've done a lot of work on this! Let me know when you think it is ready, and I'll review it.
Well, if this build doesn't break, it will work well enough for me :)
Concerning doctests however, green
ended up completely freezing when a DocTestSuite
was added to the tests with the load_tests
protocol. Unfortunately, I am not (yet) sure how to fix that, I think DocTestSuite
have a different logic that should be studied, but it doesn't really come into the scope of this PR.
Well actually, I'll add a test to make sure the bug I fixed doesn't come back, just wait some more ;)
NB: I also added a method that will flatten test suites returned by GreenTestLoader.loadTests...
methods, to make sure the returned test suite does not nest other test suites (this is easier to debug if the test suite is actually just a list instead of a nested container).
@CleanCut : I suppose you can review this PR now ! ;)
Concerning the reorganisation, these are the advantages:
unittest
framework if needed, since now the "loader" is a proper object inheriting from unittest.TestLoader
instead of collection of functions, and actually follows the unittest
API.load_tests
function at the root of a test package takes 3 arguments: loader
, tests
, pattern
, where loader is supposed to be a loader object. I was able to make it work by passing the module itself as an object load_tests(sys.modules[__name__], ...)
but because green.loader
does not use the same names as unittest.TestLoader
, users would potentially call functions using the unittest
name (as they should) instead of the green
name (for instance, loadFromModule
vs loadTestsFromModule
).unittest
code, as the current implementation only did duplicate the loadTestsFromModule
and loadTestsFromName
At some point, I would have had to create a loader class anyway, since it is required when using load_tests
: so if I had done for instance a stub class, registering the actual functions as its own methods, it would not have worked very well, because the functions themselves would have called the other functions instead of the loader methods.
Anyway, this is what I'll do right now:
DeprecationWarning
and then do what they are expected to do.One of Green's design decisions (vaguely described under "Traditional") is to only be a test runner for vanilla unittest. In other words, we intentionally avoid having anyone try to use Green as a library for replacing/extending unittest objects. This is to intentionally limit the scope of what Green tries to do and be, so that Green can be even better at what it does do. This is a different choice than other projects that choose to also provide unittest replacement/enhancement objects (pytest, nose, trial, etc.).
Given the design decision described above, making Green internals easier to integrate with something else isn't an advantage.
It is fine if we need to rename functions/methods if they need to get passed into unittest
which expects a different name. There should never be any "users" of our internal code, so internal renaming should not affect users in any way.
I am not certain what you mean about code duplication.
If we need to group stuff into the class in order for it to work passing it into unittest, then that's a great argument for organizing the stuff into the class. Lets not include anything that unittest doesn't need, though. (I haven't checked what it does or doesn't need).
There's no reason to write "wrapper" functions! No one else should be using our code...so...what would they be for?
If we need to group stuff into the class in order for it to work passing it into unittest, then that's a great argument for organizing the stuff into the class. Lets not include anything that unittest doesn't need, though. (I haven't checked what it does or doesn't need).
I'll fix that, so the GreenTestLoaded only provides the required classes.
I am not certain what you mean about code duplication.
Basically, if I'm not using a class, then I would have to copy/paste the code from unittest.TestLoader.loadTestsFromModule
and edit it to use the local green functions, whereas subclassing allows reusing the existing implementation.
Included in just-released version 2.9.0.
@althonos Thank you for all your hard work! This release was pretty much all you. :-)
Thanks ! When you use a tool daily, you just wish it gets better ;)
In regards with #87 and #88, I implemented the load_test protocol. To do so, I actually moved functions from
green.loader
to a new classgreen.loader.GreenTestLoader
, inheriting fromunittest.TestLoader
.This way, you can actually use the builtin
unittest.TestLoader.loadTestFromName
, which can runload_tests
if needed.Changes are backwards-incompatible (although some compatibility patches can be made), as I registered all functions of
green.loader
as methods ofgreen.loader.GreenTestLoader
.I also removed
green.loader.loadFromModule
as it was duplicating theunittest.TestLoader.loadFromModule
code.I added a test containing a
TestCase
that is expected to fail, but theload_tests
function in it will monkey patch theTestCase
and make the test succeed.