-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make more tests robust and independent #877
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #877 +/- ##
=======================================
- Coverage 95.6% 95.5% -0.1%
=======================================
Files 46 46
Lines 4344 4340 -4
=======================================
- Hits 4154 4148 -6
- Misses 190 192 +2
|
Most items from #797 seem addressed now. Mainly, I'm not yet sure why the tests in |
I have to admit: while I did make changes to For future reference: I have tried replicating the numbers reported in #797 (comment): called >>> 1.05 * calc_share(scen1)
0.56875
>>> calc_share(scen1)
0.5416666666666666 This seems odd since |
Today, I'm seeing these flaky errors for the first time: __________________________________ test_dl[] ___________________________________
[gw1] linux -- Python 3.9.20 /opt/hostedtoolcache/Python/3.9.20/x64/bin/python
message_ix_cli = <bound method message_ix_cli.<locals>.Runner.invoke of <message_ix.tests.conftest.message_ix_cli.<locals>.Runner object at 0x7fc27797a2b0>>
opts = ''
tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/popen-gw1/test_dl__0')
@pytest.mark.parametrize(
"opts",
[
"",
"--branch=main",
"--tag=v1.2.0",
# Nonexistent tag
pytest.param("--tag=v999", marks=pytest.mark.xfail(raises=AssertionError)),
],
)
def test_dl(message_ix_cli, opts, tmp_path):
r = message_ix_cli("dl", opts, str(tmp_path))
> assert r.exit_code == 0, (r.exception, r.output)
E AssertionError: (URLError(TimeoutError(110, 'Connection timed out')), '')
E assert 1 == 0
E + where 1 = <Result URLError(TimeoutError(110, 'Connection timed out'))>.exit_code
message_ix/tests/test_cli.py:66: AssertionError
____________________________ test_dl[--tag=v1.2.0] _____________________________
[gw0] linux -- Python 3.9.20 /opt/hostedtoolcache/Python/3.9.20/x64/bin/python
message_ix_cli = <bound method message_ix_cli.<locals>.Runner.invoke of <message_ix.tests.conftest.message_ix_cli.<locals>.Runner object at 0x7f3e3f6a8e20>>
opts = '--tag=v1.2.0'
tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/popen-gw0/test_dl___tag_v1_2_0_0')
@pytest.mark.parametrize(
"opts",
[
"",
"--branch=main",
"--tag=v1.2.0",
# Nonexistent tag
pytest.param("--tag=v999", marks=pytest.mark.xfail(raises=AssertionError)),
],
)
def test_dl(message_ix_cli, opts, tmp_path):
r = message_ix_cli("dl", opts, str(tmp_path))
> assert r.exit_code == 0, (r.exception, r.output)
E AssertionError: (URLError(TimeoutError(110, 'Connection timed out')), '')
E assert 1 == 0
E + where 1 = <Result URLError(TimeoutError(110, 'Connection timed out'))>.exit_code
message_ix/tests/test_cli.py:66: AssertionError
____________________________ test_dl[--branch=main] ____________________________
[gw1] linux -- Python 3.9.20 /opt/hostedtoolcache/Python/3.9.20/x64/bin/python
message_ix_cli = <bound method message_ix_cli.<locals>.Runner.invoke of <message_ix.tests.conftest.message_ix_cli.<locals>.Runner object at 0x7fc27797a2b0>>
opts = '--branch=main'
tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/popen-gw1/test_dl___branch_main_0')
@pytest.mark.parametrize(
"opts",
[
"",
"--branch=main",
"--tag=v1.2.0",
# Nonexistent tag
pytest.param("--tag=v999", marks=pytest.mark.xfail(raises=AssertionError)),
],
)
def test_dl(message_ix_cli, opts, tmp_path):
r = message_ix_cli("dl", opts, str(tmp_path))
> assert r.exit_code == 0, (r.exception, r.output)
E AssertionError: (URLError(TimeoutError(110, 'Connection timed out')), 'Retrieving https://github.com/iiasa/message_ix/archive/main.zip
E ')
E assert 1 == 0
E + where 1 = <Result URLError(TimeoutError(110, 'Connection timed out'))>.exit_code
message_ix/tests/test_cli.py:66: AssertionError Unfortunately, they don't provide too much information. If I'm not mistaken, the first two tests timed out retrieving the Lastly, I noticed that we didn't test calling the CLI command |
.github/workflows/pytest.yaml
Outdated
@@ -98,7 +98,7 @@ jobs: | |||
pytest message_ix \ | |||
-m "not nightly and not tutorial" \ | |||
-rA --verbose --color=yes --durations=20 \ | |||
--cov-report=xml \ | |||
--cov --junitxml=junit.xml \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, the --cov-report=xml file (coverage.xml) includes the line coverage, whereas the --junitxml file includes the results of tests.
I guess the latter is needed for Codecov to detect flaky tests. But doesn't this change also turn off generation of the former? How does Codecov then receive info on line coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to drop this commit since flaky-test-detection is going to become a paid feature sooner or later, anyway. I mainly wanted to see if it could be useful for this PR, no need to keep these changes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thorough tracking and many fixes to flaky tests! The use of isolation across the test suite now exhibits a more consistent style that can be followed by others making additions to the code.
I put some notes inline, and a few small requested changes. With those, this will be good to merge.
@@ -46,28 +50,29 @@ def output(str): | |||
else: | |||
output = print | |||
|
|||
# Identify the source directory using importlib.resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just recording for posterity that:
importlib.resources
was used in Make tests robust & independent #784 because it's in the Python standard library, thus appears to be recommended/preferred overpathlib.Path(__file__)
.- However, there are strong dissenting views from Python users.
- It was decided to switch to using
pathlib.Path(__file__)
. This reverses changes made in the earlier PR. - We don't know if this has any impact on flakiness of tests.
3bece75
to
f70e76a
Compare
Closes #797.
This is a follow-up PR to #784 with the aim of bringing even more test stability into our CI suite.
For the moment (at least while it's free), this PR experiments with codecov's new flaky-test-detection feature.
How to review
PR checklist
[ ] Add, expand, or update documentation.Just CI.