Convert mozinfo test to pytest format
Categories
(Testing :: Mozbase, defect, P3)
Tracking
(firefox108 fixed)
Tracking | Status | |
---|---|---|
firefox108 | --- | fixed |
People
(Reporter: ahal, Assigned: gbrown)
References
Details
Attachments
(1 file)
+++ This bug was initially created as a clone of Bug #1417554 +++ See bug 1397417 for the tracking bug with motivations for this change. Here is the pytest documentation: https://docs.pytest.org/en/latest/contents.html That is a lot of information, but this bug is basically about modifying 'testing/mozbase/mozinfo/tests/test.py' to make better use of pytest (it is already running under pytest, but is structured as a unittest test). This means: 1. Use 'assert foo == bar' instead of self.assertEquals(foo, bar) 2. Use module level test functions instead of unittest.TestCase based classes 3. Convert the 'verify_ip_in_list' function to a fixture which returns a function. More information on how fixtures work can be found here: https://docs.pytest.org/en/latest/fixture.html Changes can be tested with: ./mach python-test testing/mozbase/mozinfo Or on try with: ./mach try fuzzy -q "'mozbase" (or leave off the -q to choose it in the selection interface)
Reporter | ||
Comment 1•5 years ago
|
||
Bullet point 3 was accidentally copied from bug 1417554 and doesn't apply here.
Comment 2•5 years ago
|
||
(In reply to Andrew Halberstadt [:ahal] from comment #1) > Bullet point 3 was accidentally copied from bug 1417554 and doesn't apply > here. Yes, I did notice that. Thanks for clarifying.
![]() |
Assignee | |
Updated•5 years ago
|
Reporter | ||
Updated•5 years ago
|
Comment 3•5 years ago
|
||
I'd like to work on this one.
(In reply to Andrew Halberstadt [:ahal] from comment #0)
This means:
- Use 'assert foo == bar' instead of self.assertEquals(foo, bar)
What about its counterpart self.assertNotEqual(foo, bar)
? Should I change it to assert foo!= bar
?
Reporter | ||
Comment 4•5 years ago
|
||
Great, thanks for your interest!
Yes exactly, you can use any arbitrary boolean clause in the assert
statement. So whatever the semantic meaning of the old function being used, we just need to make sure we do the same thing in the assert.
Reporter | ||
Updated•5 years ago
|
Comment 5•5 years ago
|
||
I could handle most of the assert<relational-operator>()
methods, save assertRaises()
.
In resource 1, pytest.raises
helper is discussed as a context manager. I'm considering to replace all occurrences of assertRaises()
method in mozilla-central/testing/mozbase/mozinfo/tests/test.py
file with pytest.raises
helper.
In this process, I'd like to understand what do the second and third arguments to the assertRaises()
method signify?
I suppose the second argument is a callable as per 2 isn't it?
Thank you!
Reporter | ||
Comment 6•5 years ago
|
||
Yes, you have it right. The second argument is a function (or other callable), and the 3rd and 4th are the arguments you would pass into that function (if any). So you would convert this:
self.assertRaises(ValueError, func, arg1, arg2=None)
into this:
with pytest.raises(ValueError):
func(arg1, arg2=None)
Comment 7•3 years ago
|
||
Pooja: I'm releasing this bug due to inactivity. If you are still interested in working on it, please work with ahal or myself.
Updated•1 year ago
|
![]() |
Assignee | |
Comment 8•11 months ago
|
||
Updated•11 months ago
|
Pushed by gbrown@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/25b62f114f95 Convert mozinfo tests to pytest; r=ahal
Comment 10•11 months ago
|
||
bugherder |
Description
•