You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many of the Python files in Biopython still have self-tests at the end which are executed if the file is run directly via the idiom:
if__name__=="__main__":
print("Running a quick self-test")
...
This is bad for several reasons - these tests are not being run routinely via our buildbot [Update: We stopped using buildbot, but now have AppVeyor instead] or TravisCI (and therefore if the test breaks, we don't know about it), they are not counted on the coverage report https://codecov.io/github/biopython/biopython/ (and in fact actively reduce the coverage score [Update: We configured codecov to ignore the self tests]), and moreover with Python 3 making subtle changes to imports, some of these self tests have accidentally become Python 2 only.
This is a tracking issue to encourage more commits like these which move these self-tests under Tests/test_XXX.py using the unittest framework instead:
This was a quick script to count the number of (non-blank) lines after the __main__ trick (and the total number of non-blank lines) per file, reporting any over 5:
Those figures are certainly strong motivation to move the SFF self-tests into our unit-test framework. Looking back it was a mistake to write the tests that way in the first place, but I've grown to appreciated automated testing more and more over the years.
Hi @souravsingh - how about working on Bio/AlignIO/NexusIO.py moving the self-test into Tests/test_Nexus.py? Are you clear about the task, and how to submit a pull request? Thanks!
@peterjc Thank you for that I had missed test_DSSP_tool, which takes care of dssp; I have removed if name is main. I will have a look at Bio/Graphics/GenomeDiagram/_FeatureSet.py.
Cheers,
Are any files left to be done? I tried to grep self-test but only test_SffiO.py file came out. I noticed a dangling #print which I guess could be removed.
But if there is more to do I would gladly help.
Activity
peterjc commentedon May 11, 2016
Here's an indication of some obvious targets to tackle next:
This was a quick script to count the number of (non-blank) lines after the
__main__trick (and the total number of non-blank lines) per file, reporting any over 5:Remove redundant self-test in Bio.SeqIO.SwissIO
Remove redundant Bio.SeqIO.SeqXmlIO test
Remove redundant self-test
vincentdavis commentedon Sep 28, 2016
@peterjc you might want to label this easy.
peterjc commentedon Sep 28, 2016
Good point Vincent - it will vary case by case, but a lot of these should be fairly easy jobs - and the task is well defined.
vincentdavis commentedon Sep 29, 2016
For review: Considering coverage of SffIO docstests (56%) VS test_SffIO (57%) VS selftest(73%).
Attached are coverage reports for each.
Coverage_SffIO_docs.pdf
Coverage_SffIO___main__.pdf
Coverage_SffIO nostest.pdf
peterjc commentedon Sep 29, 2016
Those figures are certainly strong motivation to move the SFF self-tests into our unit-test framework. Looking back it was a mistake to write the tests that way in the first place, but I've grown to appreciated automated testing more and more over the years.
souravsingh commentedon Oct 5, 2016
@peterjc I would like to work on the issue
peterjc commentedon Oct 5, 2016
Hi @souravsingh - how about working on
Bio/AlignIO/NexusIO.pymoving the self-test intoTests/test_Nexus.py? Are you clear about the task, and how to submit a pull request? Thanks!Move Bio/SeqIO/SffIO.py self-test to Tests/test_SffIO.py & PEP8 work
peterjc commentedon Oct 6, 2016
#948 from @vincentdavis did this for
Bio/SeqIO/SffIO.pyvincentdavis commentedon Oct 7, 2016
Updated list.
(excludes not yet KGML_parser, Maxentropy, SVDSuperimposer/init.py fix)
peterjc commentedon Oct 10, 2016
KGML_parser, Maxentropy, SVDSuperimposer and UniProt/GOA done via #950, with a start on Nexus in #957.
76 remaining items
peterjc commentedon Feb 11, 2019
@svalqui you'll need to install the command line tool DSSP to try this.
It may turn out that the self-test functionality is already covered in https://github.com/biopython/biopython/blob/master/Tests/test_DSSP_tool.py (in which case we can remove the
if __name__ == "__main__":bit from https://github.com/biopython/biopython/blob/master/Bio/PDB/DSSP.pysvalqui commentedon Feb 11, 2019
@peterjc Thank you for that I had missed test_DSSP_tool, which takes care of dssp; I have removed if name is main. I will have a look at Bio/Graphics/GenomeDiagram/_FeatureSet.py.
Cheers,
Remove redundant Bio.PDB.DSSP self-test (#1929)
svalqui commentedon Feb 12, 2019
Self test on:
Bio/Graphics/GenomeDiagram/_FeatureSet.pyBio/Graphics/GenomeDiagram/_GraphSet.pyBio/Graphics/GenomeDiagram/_Track.pyare covered on Tests/test_GenomeDiagram.py
I'll remove self test.
svalqui commentedon Feb 12, 2019
I'll have a look at Bio/GenBank/Scanner.py
Remove redundant GenomeDiagram self tests (#1930)
Remove redundant self test from Bio.GenBank.Scanner (#1936)
peterjc commentedon Feb 27, 2019
These are executable code so a false positive:
Bio/bgzf.pyBio/PDB/PDBList.pyThese are all self tests to review:
Bio/PDB/PSEA.py- work in progress on Move self-test for Bio.PDB.PSEA #1336Bio/PDB/NACCESS.py- requires a key from the command line tool author to runBio/PDB/NeighborSearch.py- work started on Add selftest for Bio.PDB.NeighborSearch #1366valentin994 commentedon May 13, 2022
Are any files left to be done? I tried to grep self-test but only

test_SffiO.pyfile came out. I noticed a dangling#printwhich I guess could be removed.But if there is more to do I would gladly help.
peterjc commentedon May 23, 2022
From my comments earlier, it looks like just
Bio/PDB/PSEA.py(see #1336) andBio/PDB/NeighborSearch.py(see #1366) need addressing.Resolving issue biopython#820 in bgzf.py
peterjc commentedon May 2, 2025
Running that script again now against the current default branch:
Those three are not self-tests, but simple command line functionality.
Closing this issue as completed.
JohananOppongAmoateng commentedon Mar 7, 2026
@peterjc this issue should be closed
peterjc commentedon Mar 7, 2026
The GitHub UI made it far to easy to not actually close an issue - thank you!