Closed Bug 1397417 Opened 7 years ago Closed 2 years ago

[tracking] Convert mozbase unittests to pytest

Categories

(Testing :: Mozbase, enhancement, P3)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: ahal, Assigned: gbrown, Mentored)

References

(Blocks 1 open bug)

Details

(Keywords: meta)

Attachments

(1 file)

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.
Blocks: 1397437
Depends on: 1417554
Depends on: 1417906
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
Mozrunner and mozprofile conversion is happening as part of bug 1445944.
Depends on: 1445944
mozcrash unittests have been converted to pytest as part of bug 1441287.
Depends on: 1441287
No longer depends on: 1417906
I will use bug 1455241 to convert the mozinstall tests to pytest.
Depends on: 1455241
Priority: -- → P3
(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?
Flags: needinfo?(ahal)
Attached image Slide1.jpg (deleted) —
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.
Flags: needinfo?(ahal)
Depends on: 1490775
Severity: normal → S3
Assignee: nobody → gbrown
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: