problems
problems copied to clipboard
CS50P 2022 Refueling, unstable test.
Hi,
I'm having problems running check50
with cs50/problems/2022/python/tests/fuel
. The test for fuel.py
works fine and has no issues but the test_fuel.py
tests are acting really weird.
The result of one of the test cases is unstable. The test does not appear to be idempotent. Since the actual test logic is inside pyc
files, I've been unable to figure out why this could be happening.
Output when failing:
$ check50 --local cs50/problems/2022/python/tests/fuel
Checking......
Results for cs50/problems/2022/python/tests/fuel generated by check50 v3.3.7
:) test_fuel.py exist
:) correct fuel.py passes all test_fuel checks
:( test_fuel catches fuel.py returning incorrect ints in convert
expected exit code 1, not 0
:) test_fuel catches fuel.py not raising ValueError in convert
:) test_fuel catches fuel.py not raising ZeroDivisionError in convert
:) test_fuel catches fuel.py not labeling 1% as E in gauge
:) test_fuel catches fuel.py not printing % in gauge
:) test_fuel catches fuel.py not labeling 99% as F in gauge
To see the results in your browser go to file:///tmp/tmpw2ym49my.html
Sometimes this test gives a perfect result but any subsequent runs will result in one test failing. It's always the same test that fails.
My code:
def test_convert() -> None:
assert fuel.convert("100/100") == 100
assert fuel.convert("99/100") == 99
assert fuel.convert("3/4") == 75
assert fuel.convert("1/4") == 25
assert fuel.convert("2/3") == 67
assert fuel.convert("1/3") == 33
assert fuel.convert("1/100") == 1
assert fuel.convert("0/100") == 0
with pytest.raises(ZeroDivisionError):
fuel.convert("1/0")
with pytest.raises(ValueError):
fuel.convert("9/6")
python -VV
: Python 3.11.1 (main, Jan 6 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]