From 0b0a6cfef6eaf093ace60ab19091b45625d49e7b Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Sat, 14 Nov 2020 05:27:35 +0800 Subject: [PATCH] Replace asynctest with stdlib mock This is an implementation of https://github.com/mitmproxy/mitmproxy/issues/4020 Tested to work fine here with Python 3.8.6. --- setup.py | 1 - test/mitmproxy/addons/test_readfile.py | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 48312c510..5c1958743 100644 --- a/setup.py +++ b/setup.py @@ -102,7 +102,6 @@ setup( "dataclasses>=0.7", ], 'dev': [ - "asynctest>=0.12.0", "Flask>=1.0,<1.2", "hypothesis>=5.8,<6", "parver>=0.1,<2.0", diff --git a/test/mitmproxy/addons/test_readfile.py b/test/mitmproxy/addons/test_readfile.py index 94e18cdb3..0383beb23 100644 --- a/test/mitmproxy/addons/test_readfile.py +++ b/test/mitmproxy/addons/test_readfile.py @@ -2,7 +2,7 @@ import asyncio import io import pytest -import asynctest +from unittest import mock import mitmproxy.io from mitmproxy import exceptions @@ -54,17 +54,17 @@ class TestReadFile: tf = tmpdir.join("tfile") - with asynctest.patch('mitmproxy.master.Master.load_flow') as mck: + with mock.patch('mitmproxy.master.Master.load_flow') as mck: tf.write(data.getvalue()) tctx.configure( rf, rfile = str(tf), readfile_filter = ".*" ) - assert not mck.awaited + mck.assert_not_awaited() rf.running() await asyncio.sleep(0) - assert mck.awaited + mck.assert_awaited() tf.write(corrupt_data.getvalue()) tctx.configure(rf, rfile=str(tf)) @@ -93,16 +93,16 @@ class TestReadFile: class TestReadFileStdin: - @asynctest.patch('sys.stdin') + @mock.patch('sys.stdin') @pytest.mark.asyncio async def test_stdin(self, stdin, data, corrupt_data): rf = readfile.ReadFileStdin() with taddons.context(rf): - with asynctest.patch('mitmproxy.master.Master.load_flow') as mck: + with mock.patch('mitmproxy.master.Master.load_flow') as mck: stdin.buffer = data - assert not mck.awaited + mck.assert_not_awaited() await rf.load_flows(stdin.buffer) - assert mck.awaited + mck.assert_awaited() stdin.buffer = corrupt_data with pytest.raises(exceptions.FlowReadException): @@ -113,10 +113,10 @@ class TestReadFileStdin: rf = readfile.ReadFileStdin() with taddons.context(rf) as tctx: tf = tmpdir.join("tfile") - with asynctest.patch('mitmproxy.master.Master.load_flow') as mck: + with mock.patch('mitmproxy.master.Master.load_flow') as mck: tf.write(data.getvalue()) tctx.configure(rf, rfile=str(tf)) - assert not mck.awaited + mck.assert_not_awaited() rf.running() await asyncio.sleep(0) - assert mck.awaited + mck.assert_awaited()