Skip to content

Commit 74289d8

Browse files
committed
Harden the TestRecentlyGeneratedCanteraYaml*GasOnly tests.
If we can't find the test files: 1. if the functional test that should have made them has been collected, e.g. you're running `make test-all` or in the CI runner, then this counts as a failure. 2. if the test that should have made them has not been collected, e.g. you're just running this test on its own, or with `make test` then just mark the test as a "skip" and don't fail.
1 parent ad16116 commit 74289d8

2 files changed

Lines changed: 46 additions & 25 deletions

File tree

test/rmgpy/yaml_cantera1Test.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class TestPreviouslyWrittenCanteraYamlGasOnly(CanteraYamlFileComparer):
562562
yaml_path_1 = os.path.join(test_data_folder, 'chemkin/chem37.yaml')
563563
yaml_path_2 = os.path.join(test_data_folder, 'cantera1/chem37.yaml')
564564

565-
class TestRecentlyGeneratedCanteraYamlGasOnly(CanteraYamlFileComparer):
565+
class TestRecentlyGeneratedCanteraYaml1GasOnly(CanteraYamlFileComparer):
566566
"""Tests for comparing recently generated Cantera YAML files, gas-only mechanism.
567567
568568
These are generated on the fly in the mainTest.py functional test and stored in the testing data directory.
@@ -571,20 +571,30 @@ class TestRecentlyGeneratedCanteraYamlGasOnly(CanteraYamlFileComparer):
571571

572572
@pytest.fixture(autouse=True, scope="class")
573573
def find_recent_files(self, request):
574-
"""Find the YAML files generated by mainTest."""
575-
cantera_dir = os.path.join(self.test_data_folder, 'cantera1')
576-
chemkin_dir = os.path.join(self.test_data_folder, 'ck2yaml')
577-
578-
if not os.path.exists(cantera_dir) or not os.path.exists(chemkin_dir):
579-
pytest.skip("YAML test data directories not found. Run mainTest first.")
580-
581-
# Look for specifically named files from mainTest
582-
cantera_file = os.path.join(cantera_dir, 'from_main_test.yaml')
583-
chemkin_file = os.path.join(chemkin_dir, 'from_main_test.yaml')
584-
585-
if not os.path.exists(cantera_file) or not os.path.exists(chemkin_file):
574+
"""
575+
Find the YAML files generated by mainTest.
576+
"""
577+
cantera_file = os.path.join(self.test_data_folder, 'cantera1', 'from_main_test.yaml')
578+
chemkin_file = os.path.join(self.test_data_folder, 'ck2yaml', 'from_main_test.yaml')
579+
580+
if not (os.path.exists(cantera_file) and os.path.exists(chemkin_file)):
581+
# If mainTest's copy step was collected for this pytest session but the
582+
# files are still missing, treat that as a failure rather than a skip —
583+
# it means mainTest ran but didn't produce the expected output.
584+
# (if using pytest-randomly or pytest-ordering to reorder them this will need altering).
585+
main_test_collected = any(
586+
item.name == "test_cantera_input_files_match_chemkin_later"
587+
for item in request.session.items
588+
)
589+
if main_test_collected:
590+
pytest.fail(
591+
"from_main_test.yaml files missing even though mainTest's "
592+
"copy step was collected — it likely failed before copying."
593+
)
594+
# If mainTest wasn't collected, it's likely that we're running this test
595+
# in isolation, so skip without failing.
586596
pytest.skip("from_main_test.yaml files not found. Run mainTest first.")
587-
597+
588598
request.cls.yaml_path_1 = chemkin_file
589599
request.cls.yaml_path_2 = cantera_file
590600

test/rmgpy/yaml_cantera2Test.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -778,17 +778,28 @@ class TestRecentlyGeneratedCanteraYaml2GasOnly(CanteraYamlFileComparer):
778778

779779
@pytest.fixture(autouse=True, scope="class")
780780
def find_recent_files(self, request):
781-
"""Find the YAML files generated by mainTest."""
782-
cantera_dir = os.path.join(self.test_data_folder, 'cantera2')
783-
chemkin_dir = os.path.join(self.test_data_folder, 'ck2yaml')
784-
785-
if not os.path.exists(cantera_dir) or not os.path.exists(chemkin_dir):
786-
pytest.skip("YAML test data directories not found. Run mainTest first.")
787-
788-
cantera_file = os.path.join(cantera_dir, 'from_main_test.yaml')
789-
chemkin_file = os.path.join(chemkin_dir, 'from_main_test.yaml')
790-
791-
if not os.path.exists(cantera_file) or not os.path.exists(chemkin_file):
781+
"""
782+
Find the YAML files generated by mainTest.
783+
"""
784+
cantera_file = os.path.join(self.test_data_folder, 'cantera2', 'from_main_test.yaml')
785+
chemkin_file = os.path.join(self.test_data_folder, 'ck2yaml', 'from_main_test.yaml')
786+
787+
if not (os.path.exists(cantera_file) and os.path.exists(chemkin_file)):
788+
# If mainTest's copy step was collected for this pytest session but the
789+
# files are still missing, treat that as a failure rather than a skip —
790+
# it means mainTest ran but didn't produce the expected output.
791+
# (if using pytest-randomly or pytest-ordering to reorder them this will need altering).
792+
main_test_collected = any(
793+
item.name == "test_cantera_input_files_match_chemkin_later"
794+
for item in request.session.items
795+
)
796+
if main_test_collected:
797+
pytest.fail(
798+
"from_main_test.yaml files missing even though mainTest's "
799+
"copy step was collected — it likely failed before copying."
800+
)
801+
# If mainTest wasn't collected, it's likely that we're running this test
802+
# in isolation, so skip without failing.
792803
pytest.skip("from_main_test.yaml files not found. Run mainTest first.")
793804

794805
request.cls.yaml_path_1 = chemkin_file

0 commit comments

Comments
 (0)