Skip to content

convert all tests to pytest - #311

Merged
joanise merged 10 commits into
mainfrom
dev.ej/convert-to-pytest
Sep 10, 2026
Merged

joanise merged 10 commits into
mainfrom
dev.ej/convert-to-pytest

Conversation

@joanise

@joanise joanise commented Sep 8, 2026

Copy link
Copy Markdown
Member

PR Goal?

Wrapped up work mostly done in July: convert all tests to pytest, no more use of unittest at all.

As you can see in the commit logs, I used various regular expressions and some manual conversions in July, which was more efficient than all manual, but still time consuming. Now I decided to experiment with Codex on a simple task, and finished it all very quickly with the help of GPT 5.6 Luna, with a full line-by-line review of all proposed changes, rejecting and/or fixing what I didn't agree with.

Fixes?

Out with unittest!

Feedback sought?

normal review

Priority?

low

Tests added?

nothing but!

How to test?

uv run pytest

Confidence?

high

Version change?

no

joanise added 8 commits July 23, 2026 08:44
- test_align_cli: several conversions by hand
- sub self.assertTrue\((.*)\)$ to assert $1
- sub self.assertEqual\(([^,]*), ([^,]*)\)$ by assert $1 == $2
sub self.assertFalse\((.*)\)$ by assert not $1
sub self.assertNotEqual\(([^,]*), ([^,]*)\)$ by assert $1 != $2
sub self.assertNotIn\(([^,]*), ([^,]*)\)$ by assert $1 not in $2
sub self.assertIsNotNone\(([^,]*)\)$ by assert $1 is not None
sub with self.assertRaises\(([^,]*)\): by with raises($1):
including
sub self.assertGreater\(([^,]*), ([^,]*)\)$ by assert $1 > $2
sub self.assertIsNone\(([^,]*)\)$ by assert $1 is None
and a bunch more
Done with the help of GPT 5.6 Luna, with proposed changes reviewed
line-by-line by Eric Joanis, and code adjusted where needed.
@joanise
joanise requested a review from roedoejet September 8, 2026 22:04
@semanticdiff-com

semanticdiff-com Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  tests/test_dna_utils.py  69% smaller
  tests/test_api.py  66% smaller
  tests/test_web_api.py  63% smaller
  tests/test_anchors.py  61% smaller
  tests/test_align_cli.py  60% smaller
  tests/test_package_urls.py  59% smaller
  tests/test_misc.py  57% smaller
  tests/test_force_align.py  55% smaller
  tests/test_tokenize_cli.py  54% smaller
  tests/test_make_xml_cli.py  51% smaller
  tests/test_dna_text.py  50% smaller
  tests/test_audio.py  48% smaller
  tests/test_g2p_cli.py  48% smaller
  tests/test_temp_file.py  46% smaller
  .github/workflows/tests.yml  43% smaller
  tests/test_silence.py  42% smaller
  tests/test_dtd.py  41% smaller
  tests/test_smil.py  37% smaller
  .github/workflows/matrix-tests.yml  34% smaller
  tests/test_tokenize_xml.py  19% smaller
  tests/basic_test_case.py  5% smaller
  README.md Unsupported file format
  tests/test_config.py  0% smaller

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor
CLI load time: 0:00.04
Pull Request HEAD: 1e2f559e3623c97ea4e76003f01433d852e60b34
No imports take more than 0.1 s.

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.76%. Comparing base (732b756) to head (1e2f559).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #311   +/-   ##
=======================================
  Coverage   93.76%   93.76%           
=======================================
  Files          21       21           
  Lines        1765     1765           
  Branches      295      295           
=======================================
  Hits         1655     1655           
  Misses         73       73           
  Partials       37       37           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roedoejet roedoejet left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but I think there might be a couple very small issues. please look at the comments and fix or ignore as you see fit. Thanks Eric, this looks great!

Comment thread tests/test_g2p_cli.py

def test_non_convertible_words(self):
xml = parse_xml("<s><w>43:23</w><w>65:67</w><w>43:23</w></s>")
with self.assertLogs(LOGGER, level="WARNING"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this is removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the many cases where I was using assertLogs to hide the massive output we used to get to terminal with unittest. I've never cared whether this logged, and still don't, the relevant assertions are on the next two lines.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With pytest, it captures everything for us, so all the trouble I went to to reduce output is no longer needed. And by removing this nonsense, should you want to see that output, you are able to get it with pytest -s, instead of having to change the test code to stop hiding it.

Comment thread tests/test_anchors.py Outdated
assert words[0]["end"] <= 1.62
assert words[1]["start"] >= 1.62
assert words[8]["end"] <= 3.81
assert words[9]["start"] >= 3.81

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why'd this get changed from 3.82 to 3.81?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I must have thought it was a typo when I converted, but in fact the input data file has two anchors, one at 3.81 and one at 3.82, and the original assertions were correct. I'll fix this one.

@joanise
joanise merged commit 26dd7ba into main Sep 10, 2026
8 checks passed
@joanise
joanise deleted the dev.ej/convert-to-pytest branch September 10, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants