-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
Pytest transition #1793
Merged
Merged
Pytest transition #1793
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
222f042
[test] first pass at pytest structure for tests
wandadars 81fe0d8
[test] updated test_equilibrium to use pytest fully
wandadars b12ebbf
[test] updated test_utils to use pytest fully
wandadars eb0a53a
[test] updated test_composite to use pytest fully
wandadars 2fef131
[test] updated test_reactor to use pytest fully
wandadars b9fe294
[test] updated test_jacobian to use pytest fully
wandadars ef8d748
[test] updated test_convert to use pytest fully
wandadars 99b8b6f
[test] updated test_mixture to use pytest fully
wandadars c889d1a
[test] updated test_kinetics to use pytest fully
wandadars 19d2035
[test] updated test_transport to use pytest fully
wandadars 546860c
[test] updated test_onedim to use pytest fully
wandadars 849ccd1
[test] updated test_reaction to use pytest fully
wandadars b084204
updated test_purefluid to use pytest fully
wandadars 6216af5
[test] updated test_thermo to use pytest fully
wandadars a6ae8c7
more updates to test_func1 to use pytest
wandadars 56c9b2d
Update Pytest configuration and slow test handling
wandadars f205379
removed assertIsNan and assertIsFinite methods
wandadars 0762dca
[test] Replaced remaining unittest-style setup with pytest fixtures
wandadars adfb15f
[test] removed outdated python version check from test_composite
wandadars faeb465
[test] updated test_composite to replace assertNear with pytest approx
wandadars 7375644
[test] updated test_convert to replace assertNear with pytest approx
wandadars ab076f2
[test] added test_data_path and cantera_data_path fixtures for future…
wandadars bab1083
[test] updated test_equilibrium to replace assertNear with pytest approx
wandadars 57baf44
[test] updated test_func1 to replace assertNear with pytest approx
wandadars 7057acb
[test] updated test_jacobian to replace assertNear with pytest approx
wandadars 5728f15
[test] updated test_kinetics to replace assertNear with pytest approx
wandadars 1af83ac
[test] updated test_mixture to replace assertNear with pytest approx
wandadars cb10d55
[test] updated test_onedim to replace assertNear with pytest approx
wandadars 74ecc20
[test] updated test_purefluid to replace assertNear with pytest approx
wandadars 178a352
[test] updated test_reaction to replace assertNear with pytest approx
wandadars 9c82e6c
[test] updated test_reactor to replace assertNear with pytest approx
wandadars e37c765
[test] updated test_thermo to replace assertNear with pytest approx
wandadars 733e51d
[test] updated test_transport to replace assertNear with pytest approx
wandadars b83dcef
[test] updated test_composite to replace assertArrayNear with pytest …
wandadars cffabca
[test] Replace assertArrayNear with pytest approx
wandadars 8c9c802
[test] Restore load_yaml function; add fixtures for paths
wandadars 69bb8b8
[test] moved to test_data_path fixture where possible
wandadars 6cfb761
[test] removed class-attribute setting in jacobian tests to avoid a C…
wandadars b0e2780
[test] changed test_mixture to avoid using/setting class attributes
wandadars 2912fdb
[test] Removed class attribute usage in test_transport
wandadars f526576
[test] increased FallOff reaction test relative tolerance
wandadars 5dcf705
[test] removed the class attribute setting in test_composite
wandadars 0ed80e9
[test] reduced usage of class attributes in test_kinetics
wandadars 6504c41
[test] reduced usage of class attributes in test_reaction
wandadars 2902016
[test] addressing review comments
wandadars 55fc1f0
[test] formatting updates to test_reaction.py
wandadars 52fbb27
[test] updated tests that generated reference files to be run-able wi…
wandadars 12ce03f
[test] removed useless fixtures in test_transport
wandadars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,119 @@ | ||
import cantera | ||
import os | ||
import sys | ||
from pathlib import Path | ||
import pytest | ||
import tempfile | ||
|
||
try: | ||
from ruamel import yaml | ||
except ImportError: | ||
import ruamel_yaml as yaml | ||
|
||
pytest.register_assert_rewrite("pint.testing") | ||
|
||
TEST_DATA_PATH = Path(__file__).parents[1] / "data" | ||
CANTERA_DATA_PATH = Path(cantera.__file__).parent / "data" | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--save-reference", action="store", default=None, | ||
help="Save the reference output files for specific tests. " | ||
"Options: diffusion, counterflow_premixed, counterflow_premixed_nonideal, " | ||
"combustor, wall" | ||
) | ||
|
||
def pytest_configure(config): | ||
config.addinivalue_line("markers", "slow_test: mark test as slow") | ||
|
||
def pytest_collection_modifyitems(config, items): | ||
if os.environ.get("CT_SKIP_SLOW", "0") == "1": | ||
skip_slow = pytest.mark.skip(reason="slow test") | ||
for item in items: | ||
if "slow_test" in item.keywords: | ||
item.add_marker(skip_slow) | ||
|
||
@pytest.fixture | ||
def allow_deprecated(): | ||
cantera.suppress_deprecation_warnings() | ||
yield | ||
cantera.make_deprecation_warnings_fatal() | ||
|
||
|
||
@pytest.fixture | ||
def has_temperature_derivative_warnings(): | ||
with pytest.warns(UserWarning, match="ddTScaledFromStruct"): | ||
# test warning raised for BlowersMasel and TwoTempPlasma derivatives | ||
yield | ||
|
||
@pytest.fixture(scope="session") | ||
def test_data_path(): | ||
return TEST_DATA_PATH | ||
|
||
@pytest.fixture(scope="session") | ||
def cantera_data_path(): | ||
return CANTERA_DATA_PATH | ||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def cantera_setup(): | ||
""" | ||
Fixture to set up Cantera environment for the entire test session. | ||
""" | ||
# Add data directories | ||
cantera.add_directory(TEST_DATA_PATH) | ||
cantera.add_directory(CANTERA_DATA_PATH) | ||
cantera.print_stack_trace_on_segfault() | ||
cantera.CanteraError.set_stack_trace_depth(20) | ||
cantera.make_deprecation_warnings_fatal() | ||
|
||
# Yield control to tests | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def test_work_path(request, cantera_setup): | ||
""" | ||
Fixture to create a working directory for a test class. | ||
This will only run for class-based tests. | ||
|
||
The check on the request.cls attribute is to ensure that this fixture | ||
does not run for function-based tests. There is likely a better way to | ||
do this, perhaps by disabling autouse and using the fixture explicitly | ||
in the test classes that need it. | ||
""" | ||
|
||
if request.cls is None: | ||
# If this is not a class-based test, do nothing. | ||
yield | ||
return | ||
|
||
root_dir = Path(__file__).parents[2].resolve() | ||
if (root_dir / "SConstruct").is_file(): | ||
work_path = root_dir / "test" / "work" / "python" | ||
using_tempfile = False | ||
try: | ||
work_path.mkdir(exist_ok=True) | ||
except FileNotFoundError: | ||
work_path = Path(tempfile.mkdtemp()) | ||
using_tempfile = True | ||
else: | ||
work_path = Path(tempfile.mkdtemp()) | ||
using_tempfile = True | ||
|
||
cantera.add_directory(work_path) | ||
|
||
# Assign to the test class | ||
request.cls.test_work_path = work_path | ||
request.cls.using_tempfile = using_tempfile | ||
|
||
yield | ||
|
||
# Teardown: Remove the working directory if it was a temporary one | ||
if using_tempfile: | ||
try: | ||
for f in work_path.glob("*.*"): | ||
f.unlink() | ||
work_path.rmdir() | ||
except FileNotFoundError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[pytest] | ||
markers = | ||
slow_test: mark test as slow | ||
|
||
pythonpath = ../../build/python |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than setting it up this way, I think we should directly use the built-in
tmp_path
fixture. I don't think there's a reason to store temp files in the working tree anymore?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.
I think there is a significant benefit to the default behavior of using a directory within the source tree like
test/work/python
, which is that it makes it much easier to debug certain failing tests when you can inspect the temporary files that are being generated.