“pytest using tempfile” Réponses codées

répertoire de température pytest

def test_something_else(tmp_path):
    #create a file "myfile" in "mydir" in temp directory
    f1 = tmp_path / "mydir/myfile"
    f1.parent.mkdir() #create a directory "mydir" in temp folder (which is the parent directory of "myfile"
    f1.touch() #create a file "myfile" in "mydir"


    #write to file as normal 
    f1.write_text("text to myfile")

    assert f1.read() == "text to myfile"
Puzzled Puffin

pytest using tempfile

@pytest.fixture
def my_filepath(self, tmpdir):
    return tmpdir.mkdir("sub").join("testCurrentTicketCount.txt")
Puzzled Puffin

Réponses similaires à “pytest using tempfile”

Questions similaires à “pytest using tempfile”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code