pytest-dev/pytest-incremental

IncrementalPlugin does not use `norecursedirs` and `--ignore` options?

Opened this issue · 6 comments

Hi! This looks like an awesome package so I've been trying to get it running, but whenever I run pytest it now gets stuck forever. I've printed the trace and added some print statements, and it appears that the IncrementalPlugin ignores the norecursedirs option of my pytest config, which results in it trying to parse my entire virtual environment stored in the same folder...

The problem seems to be with this part of the code:
https://github.com/pytest-dev/pytest-incremental/blob/master/pytest_incremental.py#L577

Since I have no explicit watch path set (I want to process all files except those I explicitly ignore, such as my virtual environment), it just defaults to os.getcwd(). Is this a deliberate choice? I'm not sure how exactly pytest uses the norecursedirs option internally, but it does work correctly in the sense that if I disable pytest-incremental, it does indeed skip those folders. The same is true for the --ignore command line option.

I assume having a virtual environment in the same folder is a pretty common thing to do, so perhaps I'm missing something or doing something wrong? Thanks!

Yes, the plugin should take these options into account.

I guess no harm in ignoring vitualenvs by default as well. Any reliable way to detect those.

it just defaults to os.getcwd(). Is this a deliberate choice?

I can't image anything else to be used as default.

I assume having a virtual environment in the same folder is a pretty common thing to do, so perhaps I'm missing something or doing something wrong?

Not wrong. Although I use virtualenvwrapper & Virtual Fish, where all virtualenvs are kept on same location.

I guess no harm in ignoring vitualenvs by default as well. Any reliable way to detect those.

Good question, mine has a file pyvenv.cfg in it but that's probably not universal. I think any folder with a ./bin/python in there is probably a safe bet, but it may not catch everything.

Yes, the plugin should take these options into account.

On a related note; is there any way to specify the --inc-path arguments in a setup.cfg as well? I've tried adding watch-patch and inc-path, but neither works :(

On a related note; is there any way to specify the --inc-path arguments in a setup.cfg as well? I

I use pytest.ini. Is this setup.cfg supported by pytest? Never tried it but it should work if supported by pytest.

Is this setup.cfg supported by pytest?

It is, but looking at the docs it appears to be discouraged. I'll try using pytest.ini instead 👍

I've tried using the following pytest.ini:

[pytest]
addopts = --inc
norecursedirs = 
    ignored
    venv
    .venv
    env
    .env
    .pytype
    **/snapshots
    __pycache__
    build
    dist

Which correctly ignores these folders if I remove the addopts = --inc, but starts searching them for dependencies if --inc is enabled. So unfortunately this isn't just an artifact of using setup.cfg :(

Just ran into this issue 3 years later when I switched from virtualenvwrapper (which puts virtual environments in ~/.virtualenvs) to direnv using layout_python3 which places the virtual environment in the .direnv folder of the project directory.

Running without --inc appears to work fine. Adding ".direnv" to norecursedirs in my pyproject.toml did not resolve.

My experience is that pytest --inc does eventually work, it just takes so long that it appears to have hung...It also hoovers up memory.