Closed Bug 1395630 Opened 8 years ago Closed 7 years ago

Convert config/tests/unit-expandlibs.py to run with 'pytest'

Categories

(Testing :: Python Test, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: ahal, Assigned: raphael)

References

(Blocks 2 open bugs)

Details

Attachments

(21 files, 8 obsolete files)

59 bytes, text/x-review-board-request
ahal
: review+
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
59 bytes, text/x-review-board-request
Details
These are the only two python unittests still running with the 'unittest' framework. They each had issues when running with pytest, looks like some module import hackery messing stuff up. Once we get these working with pytest, we can delete all the 'unittest' related code from config/mozunit.py.
Blocks: 1397437
:raphael: would you be interested in looking into this?
Flags: needinfo?(rpierzina)
:davehunt Sure!
Flags: needinfo?(rpierzina)
Assignee: nobody → rpierzina
Status: NEW → ASSIGNED
Hey :ahal, as you pointed out before, it appears the way we mock out the `expandlibs_config` caused problems when switching the test runner from unittest to pytest. My patch attempts to solve this issue by leveraging pytest fixtures and mock patch for setting config values as opposed to modifying a module variable in test functions. I broke up my changes in a number of commits, each converting one original unittest test class of `unit-expandlibs.py` to pytest. Please let me know if you have any questions or would like me to make changes to this patch!
Attachment #8956466 - Flags: review?(ahalberstadt) → review+
Thanks for the conversion, I like how you split it up, makes reviewing a lot easier! That said, this should probably get a build peer stamp of approval before landing. I'll go through and provide feedback, but I'll add your patches to the build review queue so a build peer can grant the final review.
Comment on attachment 8956467 [details] Bug 1395630 - Convert TestRelativize to pytest; https://reviewboard.mozilla.org/r/225368/#review232900 ::: config/tests/unit-expandlibs-pytest.py:42 (Diff revision 1) > +def config_mock(request): > + """Replace `expandlibs_config` with a OS specific config.""" > + > + m = sys.modules['expandlibs_config'] = imp.new_module('expandlibs_config') > + > + for k, v in request.param.items(): > + setattr(m, k, v) > + > + config_mocks = [ > + mock.patch(i, new=m) for i in [ > + 'expandlibs.conf', > + 'expandlibs_exec.conf', > + 'expandlibs_gen.conf', > + ] > + ] > + > + for config_mock in config_mocks: > + config_mock.start() > + > + yield m > + > + for config_mock in config_mocks: > + config_mock.stop() It might be helpful (just from a review perspective), if the code this was replacing got deleted from the original test at the same time. I realize this would temporarily break the original test, but the build peers might want you to collapse this series down to a single commit after the review anyway.
Comment on attachment 8956469 [details] Bug 1395630 - Convert TestExpandLibsGen to pytest; https://reviewboard.mozilla.org/r/225372/#review232892 ::: config/tests/unit-expandlibs-pytest.py:140 (Diff revision 1) > +@pytest.fixture > +def tmpdir(): > + """Create a temporary directory and remove it after running the tests.""" > + d = os.path.abspath(tempfile.mkdtemp(dir=os.curdir)) > + yield d > + shutil.rmtree(d) > + > + > +@pytest.fixture > +def tmppath(tmpdir): > + """Return a function to join paths with tmpdir.""" > + > + def join(*paths): > + """Join the given paths with a temporary directory.""" > + return os.path.join(tmpdir, *paths) > + > + return join Pytest has a built-in fixture that can create temporary directories and files: https://docs.pytest.org/en/latest/tmpdir.html Might as well re-use that.
Comment on attachment 8956472 [details] Bug 1395630 - Convert TestSectionFinder to pytest; https://reviewboard.mozilla.org/r/225378/#review232904 ::: config/tests/unit-expandlibs-pytest.py:595 (Diff revision 1) > +class FakeProcess(object): > + def __init__(self, out, err=''): > + self.out = out > + self.err = err > + > + def communicate(self): > + return (self.out, self.err) Just repeating the earlier comment, but please remove the code from the old module at the same time as you add it to the new module. This will make it a lot easier to check whether you are simply copying something over, or if you are making any changes. (this is a general comment, not specifically for this piece of code)
Comment on attachment 8956473 [details] Bug 1395630 - Convert TestSymbolOrder to pytest; https://reviewboard.mozilla.org/r/225380/#review232906 ::: config/tests/unit-expandlibs-pytest.py:675 (Diff revision 1) > '.text._Z6foobarv', > '.text._ZThn4_6foobarv', > ] > > > +class TestSymbolOrder(object): This probably applies to most of the other commits too, but let's not use a class if we don't need to. I think this could just be a series of top-level functions. I also wonder if it's worth splitting this test up into multiple files (and sharing fixtures with conftest.py), but that's a question better left to the build peers.
Comment on attachment 8956474 [details] Bug 1395630 - Move converted tests to original test module; https://reviewboard.mozilla.org/r/225382/#review232908
Attachment #8956474 - Flags: review?(ahalberstadt) → review+
Attachment #8956467 - Flags: review?(ahalberstadt)
Attachment #8956468 - Flags: review?(ahalberstadt)
Attachment #8956469 - Flags: review?(ahalberstadt)
Attachment #8956470 - Flags: review?(ahalberstadt)
Attachment #8956471 - Flags: review?(ahalberstadt)
Attachment #8956472 - Flags: review?(ahalberstadt)
Attachment #8956473 - Flags: review?(ahalberstadt)
First, sorry for the delayed review, I just got back from PTO. Second, unflagging the review is equivalent to no issues. This series looks really good overall, I'd be tempted to even let it land as is if I were allowed. But there are a couple themes I'd like to see addressed before passing this on to the build peers: 1) Removing code from the old modules as it gets added to the new one (for review clarity) 2) Using top-level functions whenever classes are unnecessary. If you want, you could format this such that each TestClass in the old module gets a brand new pytest file (with shared fixtures in conftest.py). But might be best to wait on this for now. Once those are addressed, feel free to re-flag me (or flag the 'build' user on mozreview directly). Thanks again, this is really good stuff!
Just confirming this passes for me locally.
Component: General → Python Test
Summary: Convert config/tests/unit-expandlibs.py and xpcom/idl-parser/xpidl/runtests.py to run with 'pytest' → Convert config/tests/unit-expandlibs.py to run with 'pytest'
See Also: → 1445273
Attachment #8956467 - Attachment is obsolete: true
Attachment #8956468 - Attachment is obsolete: true
Attachment #8956469 - Attachment is obsolete: true
Attachment #8956470 - Attachment is obsolete: true
Attachment #8956471 - Attachment is obsolete: true
Attachment #8956472 - Attachment is obsolete: true
Attachment #8956473 - Attachment is obsolete: true
Attachment #8956474 - Attachment is obsolete: true
Hey ahal, I edited the commit history so that removed code from the old modules shows up in the same diff as it gets added to the new one and moved the tests functions outside of their respective classes. It appears using pytest's `tmpdir` fixture is problematic as the tests fail if the files are not created in the current working directory. For the sake of clarity, I renamed our fixture to not shadow pytest's fixture. Please let me know your thoughts!
Thanks, this much easier to review! Just to warn you, after the review is done, I'm probably going to ask you to fold this all back up since some of the intermediate changes will cause test/build failures :). But for now, this makes it a lot easier to review. Mike, it looks like you've modified this file the most. I've already looked over these commits and it looks good to me (though I don't have any context around this test). Do you want me to set you as the reviewer, or do I have permission to go ahead and flip these to an r+?
Flags: needinfo?(mh+mozilla)
The file is gone in bug 1429875.
Flags: needinfo?(mh+mozilla)
Doh! Sorry Raphael, looks like we may have wasted a bunch of your time :(. I'm not sure if you were planning on tackling bug 1445273 or not, but this time let's flag the test owner for needinfo before starting just to make sure the test is actually valuable in the first place.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
Attachment #8960552 - Flags: review?(ahalberstadt)
Attachment #8960553 - Flags: review?(ahalberstadt)
Attachment #8960554 - Flags: review?(ahalberstadt)
Attachment #8960555 - Flags: review?(ahalberstadt)
Attachment #8960556 - Flags: review?(ahalberstadt)
Attachment #8960557 - Flags: review?(ahalberstadt)
Attachment #8960558 - Flags: review?(ahalberstadt)
Attachment #8960559 - Flags: review?(ahalberstadt)
Attachment #8960560 - Flags: review?(ahalberstadt)
Attachment #8960561 - Flags: review?(ahalberstadt)
Attachment #8960562 - Flags: review?(ahalberstadt)
Attachment #8960563 - Flags: review?(ahalberstadt)
Attachment #8960564 - Flags: review?(ahalberstadt)
Attachment #8960565 - Flags: review?(ahalberstadt)
Attachment #8960566 - Flags: review?(ahalberstadt)
Attachment #8960567 - Flags: review?(ahalberstadt)
Attachment #8960568 - Flags: review?(ahalberstadt)
Attachment #8960569 - Flags: review?(ahalberstadt)
Attachment #8960570 - Flags: review?(ahalberstadt)
Attachment #8960571 - Flags: review?(ahalberstadt)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: