Skip to content

tmp_path and tmpdir doesn't share the same temporary directory. #4680

@WloHu

Description

@WloHu
  • Include a detailed description of the bug or suggestion
    I'm not sure if this is a bug.
    The temporary directories created by tmp_path and tmpdir for the same test item are disjoint. Check example which also shows what kind of test I wanted to write (objects which use the paths are removed).

I expected that the fixtures will operate on the same directory.

  • Minimal example if possible
OUTPUT_DIR_STR = 'some_dir'

@pytest.fixture
def output_path(tmp_path):
    return tmp_path / OUTPUT_DIR_STR

@pytest.fixture
def output_dir(tmpdir):
    return tmpdir.mkdir(OUTPUT_DIR_STR)

def test_add_file(output_path, output_dir):
    before_file = output_dir.listdir()

    output_path.mkdir()
    (output_path / 'file.txt').write_text('hi')

    after_file = output_dir.listdir()

    assert not len(before_file)
    assert len(after_file)
    assert output_dir.listdir() == after_file


def test_tmpdir_tmp_path_shared(output_path, output_dir):
    assert str(output_path) == str(output_dir)
  • pip list of the virtual environment you are using
atomicwrites     1.2.1                          
attrs            18.2.0                         
colored          1.3.93                         
coverage         4.5.2                          
filelock         3.0.10                         
flake8           3.6.0                          
hdlcontroller    0.4.1                          
lxml             4.3.0                          
mccabe           0.6.1                          
more-itertools   5.0.0                          
pip              18.1                           
pluggy           0.8.1                          
protobuf         3.6.1                          
pudb             2018.1                         
py               1.7.0                          
pyasn1           0.4.5                          
pycodestyle      2.4.0                          
pyflakes         2.0.0                          
Pygments         2.3.1                          
pyserial         3.4                            
pytest           4.1.0                          
pytest-cov       2.6.1                          
pytest-pudb      0.7.0                          
python4yahdlc    1.2.0                          
setuptools       40.6.3                         
six              1.12.0                         
toml             0.10.0                         
tox              3.6.1                          
urwid            2.0.1                          
virtualenv       16.2.0                         
wheel            0.32.3                         
xmltodict        0.11.0 
  • pytest and operating system versions
    4.20.1-arch1-1-ARCH

Metadata

Metadata

Labels

plugin: tmpdirrelated to the tmpdir builtin pluginstatus: criticalgrave problem or usability issue that affects lots of userstype: bugproblem that needs to be addressedtype: feature-branchnew feature or API change, should be merged into features branch

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions