-
Notifications
You must be signed in to change notification settings - Fork 370
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
Port test suite from spec/nose to pytest(-relaxed) #515
Comments
Legacy run on latest master yields this:
Once that same number of tests runs under pytest, this is technically done. |
Collection-level errors!
Also of note, these actually show up twice. Not sure if that's pytest-relaxed's fault or not, Invoke's suite is already spec/relaxed style in layout, so running vanilla pytest is of course a lot noisier. Aside from potential "why is collection running multiple times?" speed concerns, tho, treating this as just 2 issues. The parser/context one is irritating though since having some minor module/package nesting is a pattern I sort of like these days and it seems kinda dumb of pytest to get confused by it. Time to dig in. |
Seems pytest tries importing all tests via sys.path munging by default and the way to work around this is to just make the test packages actual packages (i.e. rub The discussion I found implied one has to do this to the However, I only added re: |
With those out of the way, it's on to other stuff like dealing with more of pytest's For example, I have a |
Latest bizarre hang-up, one of my test classes extends IntegrationSpec's setup and of course calls
Not sure what the fuck. I do note that pytest is loading the setup twice for some reason. If I remove
|
Havin a real weird hangup with some of my most complex tests/test setups, where pytest is erroneously getting mad about a "missing fixture" arg:
|
Seems the crux is (of note, master has made a lot of changes to this function, tho the little note in docstring is still there. most of the changes appear to have come from pytest-dev/pytest#2842) Further digging finds pytest-dev/pytest#2828 which seems like it almost perfectly describes the problem. Upshot's not clear though, do I need to be doing some weird shit with this Feels like better is to just dig thru how this func is breaking me in the one case but not the other, and see if I can just apply the incidental "fix" from the good case. Eg some no-op |
Yea, it's exactly what I thought, the code explicitly "skips" ahead going by number of mock patch wrappers, only grabbing the remainder as potential fixtures. Sure enough, adding a "doesn't touch anything I care about" patch decorator (including the usual bookkeeping of popping it back out of the args list) gets things working. BLARGH. |
Also of note, I would have preferred to fix this by just switching to whatever pytest's idiomatic solution is for this sort of "fixture" - except I don't recall if there are any good ways to parameterize fixture use and these decorators are heavily parameterized. Whether this was actually faster than that, IDK, but it's done for now. |
Narrowed it down to running the |
Smells like something to do with how pytest mucks around with sys.modules (eg another earlier issue was vaguely similar) and rather than go down another hour+ long rabbit hole, I think I'm just gonna rename the test suite file - it's always bothered me anyways that it "looks" a lot like it's a sub-tasks file that just happens to be in the test suite. |
Just renamed it With that...I think phase 1 complete? Also, it was finding the parser tests after all, they just got sorted after the report-breaking |
Oh, huh. Part of the issue may have just been that IntegrationSpec was no longer applied everywhere (in fact...yes! I had to remove it from the Program tests for other reasons during this work!) and it has one thing I didn't make a fixture yet - cleaning of sys.modules to "unload" all the task-module data-fixtures. Except - no, reinstating it doesn't make a difference, and the problem is that something is being unloaded too eagerly from sys.modules - the inverse of what my stuff did / does. Meh, at least it's there now. |
Now cleaning up a lot of Interestingly, from "Jeff in 2018" perspective, I realize that this case for So I've factored out the run+capture part of Leaving the "base" case of |
Seems like test suite still Just Works under Python 3. Not a big surprise given all the search and replaces were for syntax that isn't Python 3 sensitive. One weird thing I noticed is that under Python 3, coverage is way under-reporting for some reason, it's only hitting the Went back to master + having spec installed, and uh, coverage doesn't even work there under Python 3 (wacky KeyErrors about chunks?) so I suppose my earlier guess that "we never run coverage under Python 3 anyways" is accurate? Not ideal but not a blocker. |
A big ol' flake8 pass and woof, I think this is done. Feels good. EDIT: well, still gotta make sure Travis is cool with it. |
Re #515, technically speaking, but it got its own changelog entry and commit because WHY NOT
Oh hm wait Travis would possibly have been running coverage under Python 3 (insofar as the Travis config's default "run the actual tests" is usually coverage style), and for sure it is doing so now and kabooming. Seems like it did work OK under nose: https://travis-ci.org/pyinvoke/invoke/jobs/357642954#L559 |
On latest pytest-cov so that's set already. Haven't doublechecked its deptree yet. Only thing I'm finding right now on pytest-cov's tracker is pytest-dev/pytest-cov#196 (which implies it's travis-specific - something I doubt since I am getting the same symptom locally myself!) It notes rightly that the traceback fingers coverage itself as the culprit. Mine's...yea it's old. Updating it + some of its deps seems to fix it on my machine. |
Yup that did it. Toot toot. https://travis-ci.org/pyinvoke/invoke/builds/367423555 |
Background
I've moved some of my other projects over to pytest by way of my heavily-inspired-by-
spec
pytest plugin, but left Invoke for close to last as it's got by the largest test suite of my projects at this point (given I wrote it myself & it's been TDD the whole way.)Taking a quick stab at it now to see just how big a hurdle it is; if I'm lucky it'll mostly work as-is & I can switch all the tooling over, then port the idioms (eg replacing nose/spec/custom tests with
assert
, replacing some test helpers with fixtures as appropriate, etc) at whatever pace I want.Mostly I just want to avoid having to write any additional code in the old vein, eg I want my fancy asserts (esp since I've gotten used to similar goodies in modern unittest like
assertMultilineEqual
.)Also hoping for maybe a bit more speed, but suspect the now 5 full seconds long test run (!) is probably more due to hundreds of file accesses (loading configs and tasks fixtures) and subprocess overhead, than to nose being "slow".
TODO
assert_contains
etc)The text was updated successfully, but these errors were encountered: