Open Bug 1397417 Opened 3 years ago Updated 2 years ago
[tracking] Convert mozbase unittests to pytest
The |mach python-test| unittests are now run with pytest instead of python's unittest module (pytest can run unittest based tests). The pytest format is much nicer to read and write. We should take full advantage of it by converting our existing mozbase tests to the pytest format. To start, all the self.assert* methods can be replaced with simple 'asserts'. E.g: self.assertEquals(foo, bar) becomes: assert foo == bar The next step will likely be refactoring the classes into module-level test functions, with shared logic being stored in fixtures. The pytest documentation has lots of useful information: https://docs.pytest.org/en/latest/contents.html This would make a good intermediate level project for someone wanting to dip their toes in python+automation.
Hello, This my first time here (I do have the mach build/set up completed), but I'm a CS major that has dealt with a lot of python and unit testing. I think I could be of use for this bug. How can I start?
Hi, that sounds great, thanks for your interest! Mozbase is a collection of utility modules (mostly used by test harnesses), that live under testing/mozbase. It'll be best to fix one module at a time to start until you get the hang of Mozilla's (somewhat complicated) contribution process. 1) Head on over to bug 1417906 and post a comment saying you're interested (and I'll assign it to you) 2) Find mozcrash's test directory 3) Make the required changes (there are some hints in the other bug, but please feel free to ask me anything if you need help) 4) Run the tests: ./mach python-test testing/mozbase/mozcrash 5) Run the lint checks: ./mach lint --outgoing 6) Submit your patch to mozreview and flag me for review: http://mozilla-version-control-tools.readthedocs.io/en/latest/mozreview.html
mozcrash unittests have been converted to pytest as part of bug 1441287.
(In reply to Andrew Halberstadt [:ahal] from comment #0) > The |mach python-test| unittests are now run with pytest instead of python's > unittest module (pytest can run unittest based tests). The pytest format is > much nicer to read and write. We should take full advantage of it by > converting our existing mozbase tests to the pytest format. > > To start, all the self.assert* methods can be replaced with simple > 'asserts'. E.g: > self.assertEquals(foo, bar) > > becomes: > assert foo == bar > > The next step will likely be refactoring the classes into module-level test > functions, with shared logic being stored in fixtures. The pytest > documentation has lots of useful information: > https://docs.pytest.org/en/latest/contents.html > > This would make a good intermediate level project for someone wanting to dip > their toes in python+automation. Hey, I want to solve this issue, but I am unable to fork it. I tried to shallow import it to my github too, but it fails every single time. Can you please guide me through?
(In reply to Sonakshi Saxena from comment #6) > (In reply to Andrew Halberstadt [:ahal] from comment #0) > Hey, > I want to solve this issue, but I am unable to fork it. I tried to shallow > import it to my github too, but it fails every single time. Can you please > guide me through?
Andrew, can you help Sonakshi out? And, would it make sense to create another bug linked to this one focused on just a few test cases? It looks like that's what happend in comment 3 - comment 5. Sonakshi, from email it sounds like you've gotten further than failing to fork. Can you let Andrew know where you're stuck?
Thankyou Dustin! I was able to fork "mozilla-central" using - $ hg clone http://hg.mozilla.ord/mozilla-central Since, the bug contains too many test cases, I tried to focus on few initially. I have managed to convert the test files with the following path - /testing/mozbase/moztest/tests from "unittest" to "pytest." To check my files, I ran tests on the converted files- 1. test.py 2. test_resolve.py But found - "missing module" as an error in both the files. To check the authenticity of the files, I also ran the tests to the "unittest" versions of those files but ended up with the same error. I believe that I have successfully converted the files, but I am unable to run pytests on them. The attached screenshot gives more insight to the same.
Thanks for your interest in working on this bug Sonakshi. As Dustin suggested, I have raised bug 1487153 to focus on just moztest, which is where you've started. Let's move the conversation over there. Perhaps you could comment on how you're running the tests, as I suspect that may be the related to the issues you're seeing.
You need to log in before you can comment on or make changes to this bug.