Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] Fixing Unit Tests for Python 3.11 and 3.12 support #800

Merged
merged 9 commits into from
Jun 27, 2024

Conversation

kmilo9999
Copy link
Collaborator

@kmilo9999 kmilo9999 commented Jun 21, 2024

For now we decided to test the 2 latest versions and oldest supported version of python on mac, Linux, and windows for all PRs. A full-matrix test of all supported python versions performed at a longer frequency is still being considered.

This PR is aimed to fix incompatibilities found in the tests against python 3.11 and 3.12

@kmilo9999 kmilo9999 changed the title [WIP] Fixing regex matching in tests files [WIP] Fixing Python 3.11 and 3.12 support Jun 21, 2024
@kmilo9999 kmilo9999 linked an issue Jun 21, 2024 that may be closed by this pull request
@kmilo9999 kmilo9999 self-assigned this Jun 22, 2024
@kmilo9999
Copy link
Collaborator Author

@gtdang @ntolley @jasmainak @dylansdaniels
I found two problems that are making the tests fail in python 3.11+:

  1. hnn_core/tests/test_drives.py

The code is looking to raise a ValueError exception and match the error message against a specific string:

with pytest.raises(ValueError,
                           match=r'Burst duration (?s).* cannot be greater than'):

It seems that the regex rules changed in python 3.11+. It is enforced that global flags like (?s) need to be placed at the begging of the pattern. Moving the flag to the indicated position fixes the test case.

  1. hnn_core/tests/test_extracellular.py

Similar to the fist point, The code is looking to raise an AttributeError exception and match the error message against a specific string:

with pytest.raises(AttributeError, match="can't set attribute"):
        rec_arr.times = [1, 2, 3]

In this case, pythom 3.11+ changed the message of the AttributeError exception to "property X of object Y has no setter", thus the test fails matching the two strings. I couldnt find this change in the python changelog, but I found the PR that applied it.

Looking forwards for your comments.

@kmilo9999 kmilo9999 changed the title [WIP] Fixing Python 3.11 and 3.12 support [WIP] Fixing Unite Tests for Python 3.11 and 3.12 support Jun 22, 2024
@kmilo9999 kmilo9999 changed the title [WIP] Fixing Unite Tests for Python 3.11 and 3.12 support [WIP] Fixing Unit Tests for Python 3.11 and 3.12 support Jun 22, 2024
@jasmainak
Copy link
Collaborator

I'm not a regular expression expert but I trust your judgement. Can you run the CIs so I can see that they get fixed?

@kmilo9999
Copy link
Collaborator Author

I'm not a regular expression expert but I trust your judgement. Can you run the CIs so I can see that they get fixed?

Do you mean the CI in the master branch? or in this PR?

@kmilo9999 kmilo9999 marked this pull request as ready for review June 25, 2024 18:47
@kmilo9999 kmilo9999 changed the title [WIP] Fixing Unit Tests for Python 3.11 and 3.12 support [MAINT] Fixing Unit Tests for Python 3.11 and 3.12 support Jun 25, 2024
@kmilo9999 kmilo9999 requested review from ntolley and gtdang June 25, 2024 18:48
@kmilo9999
Copy link
Collaborator Author

@ntolley @gtdang It seems the unit tests are working now for python 3.11 and 3.12

Copy link
Collaborator

@gtdang gtdang left a comment

Choose a reason for hiding this comment

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

Have one minor suggestion but otherwise approve.

hnn_core/tests/test_extracellular.py Show resolved Hide resolved
@@ -13,7 +13,7 @@
strategy:
matrix:
os: [ubuntu-latest,macos-latest]
python-version: [3.8, 3.9, '3.10']
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.8, 3.11, 3.12]

Really great work getting this working @kmilo9999!

As per our discussion, I think these will be the versions we stick with for now. Definitely will be keeping in mind the idea of having a separate branch for testing the full matrix in the future

Copy link
Collaborator

@gtdang gtdang Jun 25, 2024

Choose a reason for hiding this comment

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

Ah nice catch. I was discussing with a colleague that one possibility is to have a separate full-matrix workflow that tests the main branch as a cron job. You can set up a workflow to run on a monthly or 2-week basis or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I remove 3.9 and 3.10 from the windows workflow too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@gtdang gtdang left a comment

Choose a reason for hiding this comment

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

Looks great!

@@ -13,7 +13,7 @@
strategy:
matrix:
os: [ubuntu-latest,macos-latest]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.8, 3.11, 3.12]
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you document the reason for this change on github so future developers know why it was done?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we document it at the top of this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't matter as long as it's somewhere on github! If a decision was made during a private meeting, it's generally good practice to document the reasoning on github

@gtdang
Copy link
Collaborator

gtdang commented Jun 26, 2024

@ntolley
The branch protections need to be updated for the versions we are testing. It's still looking for 3.9, which is no longer in the matrix. 3.11 and 3.12 should be added.

@ntolley ntolley merged commit ed6b3fe into jonescompneurolab:master Jun 27, 2024
12 checks passed
@ntolley
Copy link
Contributor

ntolley commented Jun 27, 2024

All set! Thanks @kmilo9999 we're all breathing much easier with the return of the green checkmarks 😄

@dylansdaniels
Copy link
Collaborator

✅ 🥳 ✅ 🥳 ✅

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.

HNN core fails with Python 3.12
5 participants