Skip to content

Running "tests/runtests.py" on Windows #13936

Closed

Description

@hunterhogan
(.venv) C:\clones\typeshed>tests\runtests -h
usage: runtests.py [-h] [--run-stubtest] [--python-version {3.9,3.10,3.11,3.12,3.13}] path

positional arguments:
  path                  Path of the stub to test in format <folder>/<stub>, from the root of the project.

...

(.venv) C:\clones\typeshed>tests\runtests.py /clones/typeshed/stdlib/ast.pyi                           
usage: runtests.py [-h] [--run-stubtest] [--python-version {3.9,3.10,3.11,3.12,3.13}] path
runtests.py: error: 'path' argument should be in format <folder>/<stub>.

Oh, oops!

(.venv) C:\clones\typeshed>tests\runtests.py stdlib/ast.pyi

...

--- TEST SUMMARY: One or more tests failed. See above for details. ---

pre-commit Success
Check structure: Success
Pyright: Success
mypy: Success
stubtest: Success
pytype: Failed
Pyright regression tests: Success
mypy regression test: Success

I troubleshoot for at least two hours, including reinstalling venv and installing editable ts_utils.

# to typeshed. Installing ts_utils editable would solve that, see

Now, pytype passes if I run it directly.

(.venv) C:\clones\typeshed\tests>pytype_test.py --print-stderr --typeshed-location /clones/typeshed \clones\typeshed\stdlib\ast.pyi 
Testing files with pytype...
Ran pytype with 1 pyis, got 0 errors.

The solution

After another 30 minutes, I am able to get:

(.venv) C:\clones\typeshed>tests\runtests.py stdlib\ast.pyi

...

--- TEST SUMMARY: All tests passed! ---

pre-commit Success
Check structure: Success
Pyright: Success
mypy: Success
stubtest: Success
pytype: Success
Pyright regression tests: Success
mypy regression test: Success

That was the solution. I didn't need to spend all that time troubleshooting and reinstalling.

from pathlib import PurePath

print(f"...in format {PurePath('<folder>', '<stub>')}")

import os.path

print(f"...in format <folder>{os.path.sep}<stub>")
(.venv) C:\clones\typeshed>C:\clones\typeshed\.venv\Scripts\python.exe c:/clones/typeshed/pp.py
...in format <folder>\<stub>
...in format <folder>\<stub>

How it looks on Linux-->

I prefer pathlib because it's a little more semantic.

Activity

  1. AlexWaygood commented on May 4, 2025

    @AlexWaygood
    Member

    Interesting! I used to use Windows, and ran this script regularly, and never ran into any problems. I believe @Avasam still uses Windows, and he was the original author of this script, so it surprises me that it doesn't work on your machine. I was under the impression that / was a valid path separator on Windows, it just wasn't the default separator.

    I don't mind too much making the changes you suggest, but I'm surprised that they're necessary. Are you able to give us any more information about your setup?

  2. Avasam commented on May 4, 2025

    @Avasam
    SponsorCollaborator

    I was under the impression that / was a valid path separator on Windows, it just wasn't the default separator.

    It is.

    Either slashes should work fine. (even prepended by ./ or .\ due to tab-completion)

    I'm guessing an issue with the pytype script (found 1-2 whilst working on #13795, I just haven't taken the time to extract them). In fact, I cannot replicate this failure on that branch (but I can on main!)

    tbf it's possible I missed issues with the pytype script (or passing args to it) as I never run it under Windows. Reason being I prefer Python 3.13 for the new REPL (and pytype doesn't support 3.13). My alternate venv is for Linux (which I just run under WSL2, almost exclusively for pytype)


    In other words, I see tests\runtests.py stdlib/ast.pyi failing as the bug.


    I generally avoid backslashes in doc/helpers because they can be very annoying to copy (copying a path on windows and deduplicating \\ is so annoying. So is copying a backslash somewhere and having it accidentally escape a character)

  3. Avasam commented on May 4, 2025

    @Avasam
    SponsorCollaborator

    Line 101 assumes filename is using system's default separator.
    Line 115 asserts.

    def _get_relative(filename: str) -> str:
    top = 0
    for d in TYPESHED_SUBDIRS:
    try:
    top = filename.index(d + os.path.sep)
    except ValueError:
    continue
    else:
    break
    return filename[top:]
    def _get_module_name(filename: str) -> str:
    """Convert a filename {subdir}/m.n/module/foo to module.foo."""
    parts = _get_relative(filename).split(os.path.sep)
    if parts[0] == "stdlib":
    module_parts = parts[1:]
    else:
    assert parts[0] == "stubs"
    module_parts = parts[2:]
    return ".".join(module_parts).replace(".pyi", "").replace(".__init__", "")

  4. AlexWaygood commented on May 4, 2025

    @AlexWaygood
    Member

    Ahh, that explains it. I never actually ran pytype_test.py on Windows (could never be bothered to get WSL setup 😃)

  5. hunterhogan commented on May 5, 2025

    @hunterhogan
    ContributorAuthor

    Yes, here is some more info. It's pretty much what @Avasam found.

    (.venv) C:\clones\typeshed>tests\pytype_test.py --print-stderr stdlib/ast.pyi
    Testing files with pytype...
    
    Traceback (most recent call last):
      File "C:\clones\typeshed\tests\pytype_test.py", line 88, in run_pytype
        ast = loader.load_file(_get_module_name(filename), filename)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\clones\typeshed\tests\pytype_test.py", line 115, in _get_module_name
        assert parts[0] == "stubs"
               ^^^^^^^^^^^^^^^^^^^
    AssertionError
    
    Ran pytype with 1 pyis, got 1 errors.
    
    stdlib/ast.pyi (3.12): AssertionError
    
    Run again with --print-stderr to get the full stacktrace.
    
    (.venv) C:\clones\typeshed>tests\pytype_test.py --print-stderr stdlib\ast.pyi
    Testing files with pytype...
    Ran pytype with 1 pyis, got 0 errors.

    installing pytype

    Ahh, that explains it. I never actually ran pytype_test.py on Windows (could never be bothered to get WSL setup 😃)

    I installed pytype in the following way. Should I trust the installation? (I do not understand wheels and eggs and unwheels or whatever the other methods are.)

    (.not_editable) C:\clones\typeshed>py -V
    Python 3.12.10
    
    (.not_editable) C:\clones\typeshed>py -m pip install -U pip
    Requirement already satisfied: pip in c:\clones\typeshed\.not_editable\lib\site-packages (25.0.1)
    ...
    Successfully installed pip-25.1.1
    
    (.not_editable) C:\clones\typeshed>pip install -r c:\clones\typeshed\requirements-tests.txt
    Ignoring pytype: markers 'platform_system != "Windows" and python_version >= "3.10" and python_version < "3.13"' dont match your environment
    ...
    Building wheels for collected packages: ts_utils
    ...
    Successfully installed aiohappyeyeballs-2.6.1 aiohttp-3.11.15 aiosignal-1.3.2 attrs-25.3.0 cfgv-3.4.0 distlib-0.3.9 filelock-3.18.0 frozenlist-1.6.0 grpcio-1.71.0 grpcio-tools-1.71.0 identify-2.6.10 idna-3.10 importlib-resources-6.5.2 libcst-1.7.0 multidict-6.4.3 mypy-1.15.0 mypy-protobuf-3.6.0 mypy_extensions-1.1.0 nodeenv-1.9.1 packaging-24.2 pathspec-0.12.1 platformdirs-4.3.7 pre-commit-4.2.0 propcache-0.3.1 protobuf-5.29.4 pyright-1.1.400 pyyaml-6.0.2 ruff-0.11.4 setuptools-80.3.1 stubdefaulter-0.1.0 termcolor-3.1.0 tomli-2.2.1 tomlkit-0.13.2 ts_utils-0.0.0 types-protobuf-6.30.2.20250503 typeshed-client-2.7.0 typing_extensions-4.13.2 uv-0.6.11 virtualenv-20.30.0 yarl-1.20.0
    
    (.not_editable) C:\clones\typeshed>pip install pytype==2024.10.11
    Collecting pytype==2024.10.11
    ...
    Successfully installed MarkupSafe-3.0.2 immutabledict-4.2.1 importlab-0.8.1 jinja2-3.1.6 msgspec-0.19.0 networkx-3.4.2 ninja-1.11.1.4 pycnite-2024.7.31 pydot-4.0.0 pyparsing-3.2.3 pytype-2024.10.11 tabulate-0.9.0 toml-0.10.2

    editable wasn't necessary

    I am very surprised that I did not need to install ts_utils as editable. (The above installation.)

    (.not_editable) C:\clones\typeshed>tests\pytype_test.py --print-stderr stdlib/ast.pyi
    Testing files with pytype...
    
    Traceback (most recent call last):
      File "C:\clones\typeshed\tests\pytype_test.py", line 88, in run_pytype
        ast = loader.load_file(_get_module_name(filename), filename)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\clones\typeshed\tests\pytype_test.py", line 115, in _get_module_name
        assert parts[0] == "stubs"
               ^^^^^^^^^^^^^^^^^^^
    AssertionError
    
    Ran pytype with 1 pyis, got 1 errors.
    
    stdlib/ast.pyi (3.12): AssertionError
    
    Run again with --print-stderr to get the full stacktrace.
    
    (.not_editable) C:\clones\typeshed>tests\pytype_test.py --print-stderr stdlib\ast.pyi
    Testing files with pytype...
    Ran pytype with 1 pyis, got 0 errors.
    
    REM for completeness
    
    (.not_editable) C:\clones\typeshed>pip list
    Package             Version
    ------------------- ---------------
    aiohappyeyeballs    2.6.1
    aiohttp             3.11.15
    aiosignal           1.3.2
    attrs               25.3.0
    cfgv                3.4.0
    distlib             0.3.9
    filelock            3.18.0
    frozenlist          1.6.0
    grpcio              1.71.0
    grpcio-tools        1.71.0
    identify            2.6.10
    idna                3.10
    immutabledict       4.2.1
    importlab           0.8.1
    importlib_resources 6.5.2
    Jinja2              3.1.6
    libcst              1.7.0
    MarkupSafe          3.0.2
    msgspec             0.19.0
    multidict           6.4.3
    mypy                1.15.0
    mypy_extensions     1.1.0
    mypy-protobuf       3.6.0
    networkx            3.4.2
    ninja               1.11.1.4
    nodeenv             1.9.1
    packaging           24.2
    pathspec            0.12.1
    pip                 25.1.1
    platformdirs        4.3.7
    pre_commit          4.2.0
    propcache           0.3.1
    protobuf            5.29.4
    pycnite             2024.7.31
    pydot               4.0.0
    pyparsing           3.2.3
    pyright             1.1.400
    pytype              2024.10.11
    PyYAML              6.0.2
    ruff                0.11.4
    setuptools          80.3.1
    stubdefaulter       0.1.0
    tabulate            0.9.0
    termcolor           3.1.0
    toml                0.10.2
    tomli               2.2.1
    tomlkit             0.13.2
    ts_utils            0.0.0
    types-protobuf      6.30.2.20250503
    typeshed_client     2.7.0
    typing_extensions   4.13.2
    uv                  0.6.11
    virtualenv          20.30.0
    yarl                1.20.0
  6. Avasam commented on May 5, 2025

    @Avasam
    SponsorCollaborator

    I am very surprised that I did not need to install ts_utils as editable. (The above installation.)

    Right now editable install of ts_utils would only be needed so that you don't need to re-install every time you do a modification.
    It would also be a nice-to-have to ensure some path locations independent of current working directory.

    pip install pytype

    That is indeed how you should install pytype. The latest version is Windows compatible.
    It's just that pytype doesn't work on Python 3.13 yet.

  7. hunterhogan commented on May 5, 2025

    @hunterhogan
    ContributorAuthor

    It would also be a nice-to-have to ensure some path locations independent of current working directory.

    Wait, are you saying "blindness to path locations" is a Python-wide issue and not merely one of the eleventy jillion things I don't know how to do?!

    hunterhogan/hunterMakesPy#1

    (I'm sorry for going so far off topic, but this issue has vexed me since my first Python modules. And thank you both for the feedback and questions. @AlexWaygood )

  8. hunterhogan commented on May 6, 2025

    @hunterhogan
    ContributorAuthor

    I was under the impression that / was a valid path separator on Windows, it just wasn't the default separator.
    @AlexWaygood

    It is.

    Either slashes should work fine. (even prepended by ./ or .\ due to tab-completion)
    @Avasam

    FYI, more precisely, a forward slash / can be valid. For example:

    (.venv) C:\apps\astToolkit>cd typeshed/stdlib
    
    (.venv) C:\apps\astToolkit\typeshed\stdlib>cd ../.. 
    
    (.venv) C:\apps\astToolkit>pushd typeshed/stdlib
    The syntax of the command is incorrect.
    
    (.venv) C:\apps\astToolkit>pushd "typeshed/stdlib"
    
    (.venv) C:\apps\astToolkit\typeshed\stdlib>pushd /?
    Stores the current directory for use by the POPD command, then
    changes to the specified directory.
    
    PUSHD [path | ..]
    
      path        Specifies the directory to make the current directory.
    
    If Command Extensions are enabled the PUSHD command accepts
    network paths in addition to the normal drive letter and path.
    If a network path is specified, PUSHD will create a temporary
    drive letter that points to that specified network resource and
    then change the current drive and directory, using the newly
    defined drive letter.  Temporary drive letters are allocated from
    Z: on down, using the first unused drive letter found.

    pushd doesn't have switches, so the cmd interpreter isn't confusing the forward slash for a switch. In this case, the forward slash is interpreted as a malformed server path, not as part of a path.

    Furthermore, the syntax for path is strict.

    (.venv) C:\apps\astToolkit>pushd 'typeshed/stdlib'
    The syntax of the command is incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions