Skip to content

Commit dcb2577

Browse files
committed
python 2+3 for unittest's mock
1 parent 0d6293e commit dcb2577

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/tests.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33

4+
import sys
45
import unittest
5-
from unittest.mock import patch, mock_open
6+
7+
if sys.version_info[0] < 3:
8+
import mock
9+
else:
10+
from unittest import mock
611

712
from bs4 import BeautifulSoup
813

@@ -135,8 +140,8 @@ def test_return_list(self):
135140
)
136141

137142

138-
@patch('csv.writer')
139-
@patch('html_table_extractor.extractor.open')
143+
@mock.patch('csv.writer')
144+
@mock.patch('html_table_extractor.extractor.open')
140145
class TestWriteToCsv(unittest.TestCase):
141146
def setUp(self):
142147
html = """
@@ -153,7 +158,7 @@ def setUp(self):
153158
"""
154159
self.extractor = Extractor(html)
155160
self.extractor.parse()
156-
mock_open()
161+
mock.mock_open()
157162

158163
def test_write_to_csv_default(self, csv_mock, _):
159164
self.extractor.write_to_csv()

0 commit comments

Comments
 (0)