-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixtures tester improvements #19
Fixtures tester improvements #19
Conversation
--HG-- rename : rst2rst/tests/__init__.py => rst2rst/tests/test_fixtures.py
this way, removals and additions show the *errors* in the current output
Allows checking multiple failing fixtures, and better reporting on tests count.
better to fail on them, if no-behavior is desirable should extend SparseNodeVisitor instead
Question: how do you run the tests? When I merge this pull request,
Are you using unittest2's test loading? Is that a nose feature?
Nice!
Could https://pypi.python.org/pypi/unittest2 help? |
Ah I'll have to look into the target, I didn't consider you'd be using that.
I feel pretty sure that it's not, there should be more tests reported after than before.
Nose has that, but it's also been added to Python 2.7+'s unittest: http://docs.python.org/2/library/unittest.html#test-discovery. And it's been backported to Python 2.4+ as unittest2: https://pypi.python.org/pypi/unittest2
Yeah, that would make the load_tests protocol available and it would be possible to create a custom test suite instead of hacking around with the introspection stuff. I think it'd end up shorter and more readable. It should also restore Python 2.5 compat' (if the package was compatible before, not sure about that) |
And what about nose's test generators? http://nose.readthedocs.org/en/latest/writing_tests.html#test-generators Line 35 in 68bae18
Line 53 in 68bae18
Tell me what you are running, so that we can adapt the
Ok, so I currently have an issue with the test loading. |
I did nothing about compatibility for multiple Python version. My priority was to implement the functionality for some python version (the one that is installed by default on my computer). |
Wouldn't something like this be more readable? class TestMeta(type):
def __new__(mcs, name, bases, dict):
for name in fixture_names():
dict['test_{name}'.format(name=name)] = lambda self: self.run_fixture(*self.fixture_paths(name))
return type.__new__(mcs, name, bases, dict) I feel this would be a fair replacement for both |
I can run the tests with |
… test_* methods, fixed compatibility with nose and unittest2 (Python 2.7).
I hope I got it! git remote add upstream [email protected]:benoitbryon/rst2rst.git
git fetch upstream
git checkout -b 19-fixtures-tester-improvements upstream/19-fixtures-tester-improvements
make develop
make test
bin/python -m unittest discover -p '*' -v The last 2 lines should give the following results: unittest: 7 tests run, 1 failed If it works for you, let's close this ticket and move forward to the other pull-requests :) |
Note: I used a function-based metaclass, because, with nose, TestMeta.new() was not triggered (I do not know why)... with a function-based metaclass, it seems to work with both nose and unittest (Python >= 2.7) |
Seems to work here as well, though if And switching to metaclasses means it works again in Python 2.6 (using either nose or unittest2), cools stuff. One thing though: in It almost works in Python 2.5 too: there are a pair of |
…) and refactored fixture_names().
Done.
Let's do it in another ticket, where we focus on compatibility with Python 2.5. |
Improved tests of fixtures.
Builds on top of #18:
visit_
anddepart_
methods, on grounds that it's easier to just blow up than have garbage outputWriterTestCase
to reify each fixture file as a test case:WriterTestCase
is 2.6+ (2.5 won't fail but won't find any test case), though most of the complexity comes from remaining compatible with 2.6: Python 2.7 merged unittest2 and introduced the load_tests protocol but in Python 2.6 autodiscovery of dynamic test cases requires:__dir__
so a sequence oftest_$thing
names can be returned to the test loader (on theTestCase
subclass itself because the test loader callsdir(testCaseClass)
, thus on a metaclass of the test case)__getattr__
on both the type (because unittest will immediately try to access the name it got on the class itself to check it's callable) and the instance (to provide the actual runner for the corresponding fixture)run_fixture
has the job of actually running the fixture