Skip to content

refactor libpdb.sanitize to avoid extending global _to_keep #1425

@rvhonorato

Description

@rvhonorato

Some time ago I added custom_topology support for libpdb.sanitize - 5dbeca5

The way it was implemented was by extending the global _to_keep:

# Get list of supported residues to keep when pre-processing
_to_keep = list(supported_residues)

if custom_topology:
custom_res_to_keep = get_supported_residues(custom_topology)
_to_keep.extend(custom_res_to_keep)

While this is not an issue for normal execution, it introduces an edge case in testing in which the order of the tests can affect this global variable and thus cause tests to fail.

Say we have a Test A which uses this list and Test B which has a side-effect of extending this global list:

Case 1:
  Test A: Pass
  Test B: Pass (extend the global)
=== Pass

Case 2:
   Test B: Pass (extend the global)
   Test A: Fail
=== Fail

Found it when debugging #1412 which was showing flaky tests and luckily this was identified because we added random order to the tests (f55ce6e)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions