treebeardtech / nbmake

📝 Pytest plugin for testing notebooks
https://pypi.org/project/nbmake/
Apache License 2.0
189 stars 18 forks source link

Glob in Windows Powershell #92

Open yasirroni opened 1 year ago

yasirroni commented 1 year ago

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):

alex-treebeard commented 1 year ago

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.

yasirroni commented 1 year ago

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.

alex-treebeard commented 1 year ago

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?

yasirroni commented 1 year ago

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 commented 1 year ago

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

alex-treebeard commented 1 year ago

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.

yasirroni commented 1 year ago
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.