pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.86k stars 2.64k forks source link

Unexpected PytestCacheWarning when passing /dev/null as config file for pytest #11502

Open ssbarnea opened 11 months ago

ssbarnea commented 11 months ago

While not really a serious bug, it seems confusing to get this behavior:

$ pytest --config-file=/dev/null --collect-only tests/fixtures/duplicate_names
============================================================================================= test session starts =============================================================================================
platform darwin -- Python 3.12.0, pytest-7.4.2, pluggy-1.3.0
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
rootdir: /dev
configfile: null
plugins: random-order-1.1.0, mock-3.11.1, plus-0.4.1.dev2, xdist-3.3.1, libtmux-0.23.2
collected 2 items                                                                                                                                                                                             
run-last-failure: no previously failed tests, not deselecting items.

<Module test_a.py>
  <Function test>
<Module test_b.py>
  <Function test>

============================================================================================== warnings summary ===============================================================================================
../../../.asdf/installs/python/3.12.0/lib/python3.12/site-packages/_pytest/stepwise.py:56
  /Users/ssbarnea/.asdf/installs/python/3.12.0/lib/python3.12/site-packages/_pytest/stepwise.py:56: PytestCacheWarning: could not create cache path /dev/.pytest_cache/v/cache/stepwise: [Errno 1] Operation not permitted: '/dev/.pytest_cache'
    session.config.cache.set(STEPWISE_CACHE_DIR, [])

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

I wanted to disable local config on purpose for debugging some behaviors and passing /dev/null is quite a common approach. Also, I would argue that having the config file on a read-only location might happen in real life.

Is there a way to avoid this warning?

dongfangtianyu commented 9 months ago

Hi, @ssbarnea

I'm unable to reproduce this warning in Windows and Ubuntu 24

Bold analysis of the reason:

pytest regards the file storing the configuration location as rootdir
and then attempts to create cachedir under rootdir.

Solution approach: Disable cachedir

You can suggest trying the following command:

pytest -c /dev/null -o cache-dir=/dev/null