Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pytest temp directory

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"
Comment

pytest using tempfile

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

PREVIOUS NEXT
Code Example
Python :: what is type 
Python :: Exception Type with except block: 
Python :: python allow null argument 
Python :: violajones python opencv 
Python :: python crear variables 
Python :: create a distance matrix from a coordinate matrix in python 
Python :: assertRaises property 
Python :: print hello in python 
Python :: python as-lookup 
Python :: python redirect console output to devnull 
Python :: split() method, sep=i, n=veces aplicado 
Python :: how to sum 2 no.s in python 
Python :: quicksort python 
Python :: get user id discord.py 
Python :: np.all() 
Python :: text python 
Python :: python polymorphism 
Python :: pandas integer to date 
Python :: how to create a window in pygame 
Python :: django rest framework viewset 
Python :: Adding new column to existing DataFrame in Pandas 
Python :: for range python 
Python :: round down number python 
Python :: plt title color 
Python :: how to read frame width of video in cv2 
Python :: python dictionary if not found 
Python :: inline for python 
Python :: reverse the string in python 
Python :: find the range in python 
Python :: what is a thread in os 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =