Skip to content
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

Glob in Windows Powershell #92

Open
yasirroni opened this issue Dec 26, 2022 · 7 comments
Open

Glob in Windows Powershell #92

yasirroni opened this issue Dec 26, 2022 · 7 comments

Comments

@yasirroni
Copy link

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
@alex-treebeard
Copy link
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.

@yasirroni
Copy link
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.

@alex-treebeard
Copy link
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?

@yasirroni
Copy link
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"]

@yasirroni
Copy link
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

@alex-treebeard
Copy link
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.

@yasirroni
Copy link
Author

yasirroni commented Feb 26, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants