Skip to content

Glob in Windows Powershell #92

Open

Description

@yasirroni

Describe the bug
Run pytest --nbmake -n=auto **/*ipynb get no file in Powershell

To Reproduce
Steps to reproduce the behavior:

  1. Run pytest --nbmake -n=auto **/*ipynb

Expected behavior
Works like in the doc

Desktop (please complete the following information):

  • OS: Windows

Activity

  1. alex-remedios commented on Feb 12, 2023

    @alex-remedios
    Member

    hi @yasirroni , sorry I am late responding to this.

    I don't have a windows device and generally restrict testing to Linux. Were you able to resolve this problem? If so, please share how.

  2. yasirroni commented on Feb 12, 2023

    @yasirroni
    Author

    I haven't been able to resolve it. The one package that I know can do something like that is jupytext. I hope I can make a PR for windows later if I got the time.

  3. alex-remedios commented on Feb 13, 2023

    @alex-remedios
    Member

    I see. I don't think we can expect this to work on windows as documented, the best course of action for this case may be:

    1. Either we solve this by fixing the glob expression -- powershell may have a different way of doing this to bash (blog)
    2. We rely on pytest's features for specifying/selecting tests (docs). In this case you would pass the whole directory to pytest e.g. pytest --nbmake . and add arguments for selecting your notebooks.

    Are you able to find a way to do this natively with powershell?

  4. yasirroni commented on Feb 21, 2023

    @yasirroni
    Author

    MWE that working:

    pytest -c pyproject.toml --nbmake

    with pyproject.toml file:

    [tool.pytest.ini_options]
    testpaths = ["tests", "notebooks"]

    But, if there is a .py files in notebooks/ dir, it will also be tested by pytest. I haven't know how to make all .py on tests/ and .ipynb in notebooks/.

    Don't forget to ignore checkpoints:

    [tool.pytest.ini_options]
    testpaths = ["tests", "notebooks"]
    norecursedirs = ["hooks", "*.egg", ".eggs", "dist", "build", "docs", ".tox", ".git", "__pycache__", ".ipynb_checkpoints"]
  5. yasirroni commented on Feb 21, 2023

    @yasirroni
    Author

    But, as far as I understand, pytest --nbmake -n=auto **/*ipynb means that **/*ipynb belongs to nbmake parameters (not pytest parameters)? If yes, implementing glob inside nbmake and pass that to pytest should be possible? #CMIIW

  6. alex-remedios commented on Feb 21, 2023

    @alex-remedios
    Member

    When you enter **/*ipynb into the shell. It is expanded by the interpreter (on linux this is bash, on windows this is powershell).

    Pytest and nbmake receive the output of the expanded **/*ipynb (which is x.ipynb y.ipynb ...)

    If I'm correct, we shouldn't implement wildcards again in pytest/nbmake because it violates the single responsibility principle.

    Are you able to share with me the output from pytest --nbmake --collect-only?

    We can use the collected names to form a selector.

  7. yasirroni commented on Feb 26, 2023

    @yasirroni
    Author
    platform win32 -- Python 3.8.10, pytest-7.2.0, pluggy-1.0.0
    rootdir: PATH, configfile: pyproject.toml, testpaths: tests, notebooks
    plugins: anyio-3.6.2, nbmake-1.3.5, cov-4.0.0, lazy-fixture-0.6.3, mock-3.10.0, xdist-3.1.0
    collected 23 items
    
    <Package tests>
      <Module test_NAMEt.py>
        <Function test_TESTNAME1>
        <Function test_TESTNAME2>
        <Function test_TESTNAME3>
        <Function test_TESTNAME>
    <NotebookFile notebooks/NOTEBOOK1.ipynb>
      <NotebookItem >
    <NotebookFile notebooks/NOTEBOOK2.ipynb>
      <NotebookItem >
    

    Note that I already separate my tests to testpaths: tests (for py files), notebooks (for ipynb files, no longer any py files)

    This issue can be closed actually because config solve it. But, this issue could tell other users when they are using this package at the first time and see that bare pytest --nbmake -n=auto **/*ipynb could not find any files, come here, understand that they need at least include config for windows user.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions