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
unittest cannot load module whose name starts with Unicode #68451
Comments
|
Because VALID_MODULE_NAME is r'[_a-z]\w*\.py$' in unittest/loader.py. Using r'[^\\W\\d]\w*\.py$' insteaded. |
|
Are the module names valid in import statements? it would help if you could perhaps attach a little tar/zip file with an example failure. |
|
There is an attached file for examples. I ran and got |
|
By the way, I ran with Python 3.4.0. |
|
r'[^\\W\\d]\w*' doesn't match all valid Python identifiers. It would be more correct to write the check as: |
|
Yes, I bet that regex is left over from python2, where we didn't have isidentifier. |
|
Thank you. |
|
update by adding `except AttributeError:` |
|
Thank you very much for writing your patch in backwards compatible style - it will make backporting to unittest2 much easier. |
|
I'm torn on whether this needs a test or not. It would be hard to regress, but testing this properly really wants hypothesis with a valid-python-identifier-strategy. I think on balance we do need one. So - we need a test in test_discover that mocks the presence of a file with a name containing e.g. \u2603. |
|
sih4sing5hong5 - I think we do need a test in fact - it can be done using mocks, but right now I think the patch has a bug - it looks for isidentifier on $thing.py, but not on just $thing (which we need to do to handle packages, vs modules). |
|
Add PR: #1338 rbcollins: Need for help to review the patch, I think that both |
|
The original PR refers to a branch that no longer exists, but the behaviour documented still applies to master. There were some changes to the test loader, but none that fixed this issue. |
|
thanks, will wait for a review from Serhiy, Rbcollins or ezio |
|
What is the current error on test_dir.tar.gz? I'm not sure which problem is trying to be solved here. Why does PR 13149 use str.isidentifier() method? unittest doesn't allow arbitrary Unicode in filenames? |
|
From the description, I think the bug is that filenames that *begin* with non-ascii are not searched for tests. Looking at the test_dir.tar.gz contents, this is the test case that I'd use: Broken: $ python3 -m unittest discover -vv -p '*.py'
test_走 (tests試驗.Test試驗.試驗) ... ok
test_走 (tests試驗.test試驗.試驗) ... okRan 2 tests in 0.000s OK Corrected: ---------------------------------------------------------------------- OK isidentifier() is used because filenames to be discovered must be importable and thus valid identifiers: https://docs.python.org/3/library/unittest.html#test-discovery |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: