citation-file-format / cffconvert

Command line program to validate and convert CITATION.cff files.
Apache License 2.0
95 stars 28 forks source link

Order in testing can make the tests fail #343

Closed jspaaks closed 1 year ago

jspaaks commented 1 year ago
cd $(mktemp -d --tmpdir cffconvert.XXXXXX)
git clone https://github.com/citation-file-format/cffconvert .
git checkout 645dc46192e208853b7568570de1bb5feeca50f1
python3 -m venv venv
source venv/bin/activate
pip install .[testing]
pytest tests # all ok
mv tests/cff_1_3_0 tests/bff_1_3_0
pytest tests # fails at the first YAML based version test after doing a JSON based test
(some output omitted)
tests/bff_1_3_0/urls/_____/test_zenodo_object.py::TestZenodoObject::test_upload_type PASSED                                                                 [ 44%]
tests/bff_1_3_0/urls/_____/test_zenodo_object.py::TestZenodoObject::test_version PASSED                                                                     [ 44%]
tests/cff_1_0_3/a/test_apalike_object.py::TestApalikeObject::test_as_string FAILED                                                                          [ 44%]

============================================================================ FAILURES =============================================================================
________________________________________________________________ TestApalikeObject.test_as_string _________________________________________________________________

self = <tests.cff_1_0_3.a.test_apalike_object.TestApalikeObject object at 0x7f06fae4ee00>

    def test_as_string(self):
>       actual_apalike = apalike_object().add_all().as_string()

tests/cff_1_0_3/a/test_apalike_object.py:20: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/cffconvert/cff_1_x_x/apalike.py:46: in add_all
    .add_year()     \
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <cffconvert.cff_1_0_x.apalike.ApalikeObject object at 0x7f06f8fbb970>

    def add_year(self):
        if "date-released" in self.cffobj.keys():
>           self.year = "(" + str(self.cffobj["date-released"].year) + ")."
E           AttributeError: 'str' object has no attribute 'year'

src/cffconvert/cff_1_0_x/apalike.py:24: AttributeError
===================================================================== short test summary info =====================================================================
FAILED tests/cff_1_0_3/a/test_apalike_object.py::TestApalikeObject::test_as_string - AttributeError: 'str' object has no attribute 'year'

It seems there may be some carry-over from the JSON based schema used in the tests preceding the error. Caching related maybe?

jspaaks commented 1 year ago

Somehow YAML seems to remember that I'm setting the parser to read dates as strings when cff-version is 1.2.0 or 1.3.0. If you then come back to it later with a different cff file that has cff-version 1.1.0 or 1.0.x, it uses the parser configured for later cff versions.

jspaaks commented 1 year ago

Fixed in PR #344, closing