Closed Bug 1490775 Opened 6 years ago Closed 2 years ago

Convert mozinfo test to pytest format

Categories

(Testing :: Mozbase, defect, P3)

defect

Tracking

(firefox108 fixed)

RESOLVED FIXED
108 Branch
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)
Bullet point 3 was accidentally copied from bug 1417554 and doesn't apply here.
Assignee: nobody → stevea1
Status: NEW → ASSIGNED
(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.
Priority: -- → P3
Assignee: stevea1 → nobody
Status: ASSIGNED → NEW

I'd like to work on this one.

(In reply to Andrew Halberstadt [:ahal] from comment #0)

This means:

  1. 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?

Flags: needinfo?(ahal)

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.

Flags: needinfo?(ahal)
Assignee: nobody → poojagadige
Status: NEW → ASSIGNED

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!

Flags: needinfo?(ahal)

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)
Flags: needinfo?(ahal)

Pooja: I'm releasing this bug due to inactivity. If you are still interested in working on it, please work with ahal or myself.

Assignee: poojagadige → nobody
Status: ASSIGNED → NEW
Severity: normal → S3
Assignee: nobody → gbrown
Status: NEW → ASSIGNED
Pushed by gbrown@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/25b62f114f95 Convert mozinfo tests to pytest; r=ahal
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 108 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: