Skip to content

Use features from Pytest and remove Unittest #128

@bryanwweber

Description

@bryanwweber

Abstract

Pytest has a bunch of nice features that have potential to make the Python test code shorter, easier to read, and potentially faster. Recent work has made it possible to use Pytest with the existing unittest-based suite, but I'm interested in exploring what we can get if we drop unittest altogether.

Motivation

Hoping to improve the test suite. Wanting to use Pytest features like fixtures to simplify the test code.

Description

I've been working on a branch over here: https://github.com/bryanwweber/cantera/tree/use-pytest, specifically, I've copied almost all the tests from the test_purefluid.py file into a new file (test_purefluid_pytest.py). The code is about 100 lines shorter, but it's missing a bunch of comments and such that we'd probably want to copy over, and the sample data has been copied out into YAML files. On the other hand, it doesn't require any of the utilities.CanteraTest infrastructure yet, so that would save some lines... So, so far, there hasn't been much benefit in terms of lines of code.

I haven't timed it yet either. Arguably, the code is easier to read, but it's really largely the same. I do like the new create_fluid fixture for the various PureFluid tests.

The main benefit I see so far is standardizing on np.isclose to test floating point numbers rather than our bespoke assertNear. math.isclose or pytest.approx would be more-or-less equivalent.

I'm putting this up as a work-in-progress issue because I've started work on it, but if there doesn't seem to be a real benefit, I'm fine with dropping it. I might like to try one more file, maybe a more complicated case, to see if there's any real benefit from fixtures over the CanteraTest class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    work-in-progressAn enhancement that someone is currently working on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions