Page MenuHomeSoftware Heritage

tests: Hide utilities from stack traces
ClosedPublic

Authored by vlorentz on Thu, Nov 4, 5:53 PM.

Details

Reviewers
anlambert
Group Reviewers
Reviewers
Summary

They clutter the test output because pytest prints the whole code
of the function raising the assertionerror.

With this magic variable, the error is shown as if it was raised
directly in the caller's body.

Diff Detail

Repository
rDLDBASE Generic VCS/Package Loader
Branch
releases-T3636
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 24882
Build 38869: Phabricator diff pipeline on jenkinsJenkins console · Jenkins
Build 38868: arc lint + arc unit

Event Timeline

Build is green

Patch application report for D6612 (id=24009)

Could not rebase; Attempt merge onto 5063082e7d...

Updating 5063082..177e41e
Fast-forward
 docs/package-loader-tutorial.rst                 |  25 +++
 swh/loader/package/archive/tests/test_archive.py |  20 +--
 swh/loader/package/cran/tests/test_cran.py       |  20 ++-
 swh/loader/package/debian/tests/test_debian.py   |  80 +++++----
 swh/loader/package/deposit/loader.py             |   5 -
 swh/loader/package/deposit/tests/test_deposit.py |  78 +++++++--
 swh/loader/package/nixguix/tests/test_nixguix.py |  31 +++-
 swh/loader/package/npm/tests/test_npm.py         |  83 ++++-----
 swh/loader/package/opam/loader.py                |  41 ++++-
 swh/loader/package/opam/tests/test_opam.py       |  83 ++++++++-
 swh/loader/package/pypi/tests/test_pypi.py       | 205 ++++++++++++-----------
 swh/loader/tests/__init__.py                     |  18 +-
 swh/loader/tests/test_init.py                    |   4 +-
 13 files changed, 460 insertions(+), 233 deletions(-)
Changes applied before test
commit 177e41e1f4a53f117cdf9ec8f5d2939e8a446bac
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Nov 4 17:53:20 2021 +0100

    tests: Hide utilities from stack traces
    
    They clutter the test output because pytest prints the whole code
    of the function raising the assertionerror.
    
    With this magic variable, the error is shown as if it was raised
    directly in the caller's body.

commit dffd6387dfcdc4bb535c13916299d246c0f4d169
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Nov 4 15:49:45 2021 +0100

    package loaders: Make test failures more helpful
    
    Some tests did the following:
    
    1. build a snapshot
    2. get the snapshot from the storage
    3. compare it with the expected snapshot
    4. get the origin visit from the storage and check it
    
    If the loader built a wrong snapshot, the test fails at step 2,
    and the only information displayed is that the expected snapshot id
    does not exist, which is very unhelpful.
    
    Instead, I reordered them as: 1, 4, 2, 3. This way, if a wrong
    snapshot is build by the loader, it is detected when comparing
    the visit, and pytest shows the two hashes.
    Then, the test can be modified to use the hash that is actually
    generated to show the actual snapshot.
    
    This is consistent with what was already done in the pypi loader.
    
    Additionally, I made the following changes:
    
    1. always check stats last (because a difference in numbers is
       hardly actionable without testing other objects)
    2. add a few more snapshot id checks in visits
    3. deduplicated a hardcoded snapshot id.

commit 65ee04b10025474c59e0521aab7b847a74b38b00
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Oct 21 14:35:47 2021 +0200

    deposit: Remove 'parent' deposit
    
    The parent is computed by the deposit as the revision of the latest deposit
    in the same origin before the current one.
    Therefore, it is redundant, as it can be recomputed from metadata
    + revision date.
    
    This is a preliminary change needed to make package loaders produce
    releases instead of revisions, as releases don't have parent relationships

commit 0d04182ecce3ab34c2ed648bbafa83ab5204e0b0
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Nov 4 11:45:36 2021 +0100

    opam: Write package definitions to the extrinsic metadata storage

commit 18bbbae719fc9d165d5b543e54d449f5befc083a
Author: Valentin Lorentz <vlorentz@softwareheritage.org>
Date:   Thu Nov 4 11:43:53 2021 +0100

    Add missing documentation for `get_metadata_authority`.

See https://jenkins.softwareheritage.org/job/DLDBASE/job/tests-on-diff/597/ for more details.

anlambert added a subscriber: anlambert.

Cool, nice pytest trick to know !

This revision is now accepted and ready to land.Fri, Nov 5, 11:22 AM