Repository navigation
Add type annotations - #33
stephenfin wants to merge 5 commits into
Conversation
jelmer
left a comment
There was a problem hiding this comment.
-
The new
debug=Truebranch inOptimisingTestSuite.runisn't explained that I can see. If the goal is to matchunittest.TestSuite.run's signature, it is worth saying so in the commit message and the NEWS entry - and if it isn't, I'd drop it from this PR and propose it on its own, since it ships two new behaviours (callingtest.debug(), propagating exceptions) without a motivation. -
Please add a note to NEWS that
addTestnow rejects non-unittest.TestSuiteiterables; it's a visible behaviour change even if the new signature makes it defensible. -
test_none_resource_can_be_shared_reset_and_releasedreaches into_resourceand_getCurrentResourceand sequences a lot of state changes in one test. Can it be tightened to just the observable behaviour (dirty/reset/finishedWith lifecycle withNone), without peeking at the box?
|
Marking as draft while I work on this. I've split the Python changes out into #34 since they don't depend on this. |
Yeah, this was a bug (IMO) since anyone calling
Agreed. Done.
Yeah, I wasn't happy with this but wanted something to ensure my changes from |
|
btw, do we want to enable issues here and disable the projects and wiki features? Asking here since I don't have another forum to do so. |
'unittest.TestSuite.run()' provides a 'debug' flag [1], which can be passed explicitly or implicitly by calling 'unittest.TestSuite.debug()' [2]. When passed, it calls 'debug()' on the 'TestCase' rather than '__call__()' [3]. We didn't support this parameter in 'OptimisingTestSuite.run', meaning anyone calling the inherited 'debug()' method would see a TypeError. Fix this and accept the 'debug' argument. Copy the behavior of the parent class and call 'test.debug()' when it is enabled. This lets test exceptions propagate to the caller instead of being collected in the result, while leaving normal test execution unchanged. [1] https://github.com/python/cpython/blob/v3.11.0/Lib/unittest/suite.py#L102 [2] https://github.com/python/cpython/blob/v3.11.0/Lib/unittest/suite.py#L135 [3] https://github.com/python/cpython/blob/v3.11.0/Lib/unittest/suite.py#L121-L124 Signed-off-by: Stephen Finucane <stephen@that.guru>
'OptimisingTestSuite.addTest()' currently treats any iterable as a suite but this isn't a great signal: not only can it cause us to mistake a test case for a test suite if it happens to implement iteration but it's also very difficult to type check. Instead of the try-except on 'iter', use an 'isinstance' check against 'unittest.TestSuite' and pass everything else through to the parent 'addTest()' method. This has potential runtime impacts if someone is passing iterable suite-like objects that do not inherit from 'unittest.TestSuite', but that seems unlikely and callable objects accepted by the base 'addTest()' can still be added as individual tests. Signed-off-by: Stephen Finucane <stephen@that.guru>
This is a first pass that simply gets mypy passing in strict mode. There is a lot of room for improvement here, particularly around describing the types returned by TestResourceManager methods (currently typed as 'object') but we will tackle those separately, as follow-ups. Signed-off-by: Stephen Finucane <stephen@that.guru>
This allows users to be a lot more expressive in their tests, should they so wish. Signed-off-by: Stephen Finucane <stephen@that.guru>
Yeah, that would be good. We'll need a project admin for that though, which I am not. @rbtcollins |
This looks more complicated that it is, but the commit-by-commit view should help with review. I can split this up into multiple PRs if needed.
Commits
Support debug mode in OptimisingTestSuite.runRestrict suite unwrapping to unittest.TestSuiteAdd mypyAdd types to package and enable strict modeMake TestResourceManager a generic