nbmake icon indicating copy to clipboard operation
nbmake copied to clipboard

Glob in Windows Powershell

Open yasirroni opened this issue 2 years ago • 7 comments

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

yasirroni avatar Dec 26 '22 09:12 yasirroni

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.

alex-treebeard avatar Feb 12 '23 16:02 alex-treebeard

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.

yasirroni avatar Feb 12 '23 22:02 yasirroni

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?

alex-treebeard avatar Feb 13 '23 14:02 alex-treebeard

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"]

yasirroni avatar Feb 21 '23 08:02 yasirroni

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

yasirroni avatar Feb 21 '23 08:02 yasirroni

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.

alex-treebeard avatar Feb 21 '23 10:02 alex-treebeard

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.

yasirroni avatar Feb 26 '23 15:02 yasirroni