Open trexfeathers opened 9 months ago
Sorry for the janky formatting - reached the character limit. But it's here as a proof of concept that could be automated.
Ping @ESadek-MO
Hi @trexfeathers Nice work, but a couple of things bothering me :
Firstly, it would be much handier to have a full path to each test module in the table Was this due to the line-length constraint you mention ?
Secondly, I think the entry for test_netcdf__loadsaveattrs is showing some problems :
It is saying |
%pytest | name | N-unittest | N-pytest |
---|---|---|---|---|
15 | test_netcdf__loadsaveattrs | 127 | 23 |
But actually, this module is entirely written in pytest. So something odd here ?
@pp-mo
Firstly, it would be much handier to have a full path to each test module in the table Was this due to the line-length constraint you mention ?
100% - I did originally have the full path and it was even a link.
Secondly, I think the entry for
test_netcdf__loadsaveattrs
is showing some problems : It is saying%pytest name N-unittest N-pytest 15 test_netcdf__loadsaveattrs 127 23 But actually, this module is entirely written in pytest. So something odd here ?
Good spot! That was copy-pasta. I have updated
-assert_calls_methods = filter(lambda c: hasattr(c.func, "value"), calls)
+assert_calls_methods = filter(lambda c: hasattr(c.func, "value"), assert_calls)
pytestify is excellent, so if you can get a given test module to a point where it is using unittest.TestCase
rather than a bespoke Iris test class, the rest should be is easy.
Apologies if I'm teaching Granny to suck eggs.
if you can get a given test module to a point where it is using
unittest.TestCase
rather than a bespoke Iris test class, the rest should be is easy
I may have misunderstood. If I've understood correctly, then I don't think this is realistic. The use of IrisTest
is super embedded throughout our testing. Things like get_data_path()
, assertCML()
and assertArrayEqual()
are everywhere. Rewriting the tests to a point where an auto-converter can handle them would likely take a similar amount of time to just converting to PyTest ourselves.
Bonus points: if we manage to agree on some common conventions (e.g. how we use fixtures, conftest.py
etcetera) BEFORE converting anything, then a tracker such as the above could also double up as a tracker of where we have rolled out these conventions (with a 5% error for the PyTest usages we have already written!)
Some methods inherited from unittest
will need replacing with pytest friendly equivalents. For developer convenience while translating, here is a table of unittest
methods and their replacement code. Feel free to add to or edit this table as appropriate.
unittest method |
pytest equivalent |
---|---|
assertTrue(x) |
assert x |
assertFalse(x) |
assert not x |
assertRegex(x, y) |
assert re.match(y, x) |
assertRaisesRegex(cls, msg_re) |
with pytest.raises(cls, match=msg_re) |
@staticmethod
on a fixture
E AttributeError: 'staticmethod' object has no attribute '__name__'
"
Iris approximate pytest adoption
Generated using this script
Click to expand this section...
```python import ast from pathlib import Path from sys import argv # Also requires the `tabulate` package. import pandas as pd if not (len(argv) == 2 and Path(argv[1]).exists()): message = "Correct script usage = `pytest_adoption.pyClick to expand this section...
\n\n" "```python\n" f"{Path(__file__).read_text()}" "```\n\n" "Total adoption
548 out of 10272 : 5%
Breakdown