In pytesting, how to provide the link/pointer to the file/image for uploading the image in flask
<p>I am using flask with python 3.5 and try to test my code with pytest for uploading the image.I have gone through various answers but sadly couldn't get the point to solve my problem.In link of github, it explains how to use filename, file_field
<a href="https://gist.github.com/DazWorrall/1779861" rel="nofollow">https://gist.github.com/DazWorrall/1779861</a>
I tried in that way also but i wasn't going in right direction. Please help me in solving my problem. Here, post method is used to upload the image, content-part should be multi-part but regarding data, how to send the image data and its path.</p>

<pre><code>test_client.post(
    '/uploadimage',
    content_type='multipart/form-data',
    buffered=True,
    data=dict(
        file='user4.jpg', file_field=io.BytesIO(b"~/Downloads/images/")),
    follow_redirects=True)
</code></pre>

<p>In here, while running for pytest it doesn't recognise the file. Dont know why? I will hope to get my answer soon.. Thanks.</p>

<p>res = test_client.post(
        products_url,
        content_type='multipart/form-data',
        buffered=True,
        data={
            'file': (io.BytesIO(b'~/Downloads/images'), 'user4.jpg'),
        })</p>

<p>Little bit change the way data is send.
It is working fine for me.</p>

python flask py.test