-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python_test_example #6
Comments
What is Tests have 3 possible outcomes:
https://pymotw.com/2/unittest/ ok_fail_error.py from unittest import TestCase, main
class OkFailErrorTestCase(TestCase):
def test_ok(self):
self.assertEqual(1, 1)
def test_fail(self):
self.assertEqual(1, 2)
def test_error(self):
import requests
self.assertEqual(1, 1)
if __name__ == '__main__':
main()
|
$ python3
>>> from mock import Mock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mock'
>>> from unittest.mock import Mock
>>> m = Mock()
>>> m
<Mock id='4449643664'>
>>> m()
<Mock name='mock()' id='4449643728'>
>>> m.return_value = 25
>>> m
<Mock id='4449643664'>
>>> m()
25
>>> m.a
<Mock name='mock.a' id='4449643728'>
>>> m.a = 10
>>> m.a
10
>>> m.a.return_value = 20
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'return_value'
>>> |
|
|
|
def setUp(self):
self.load_model_patcher = patch('flask_app.model.load_model')
self.load_model_m = self.load_model_patcher.start()
from flask_app.app import app
self.client = app.test_client()
def tearDown(self):
self.load_model_patcher.stop() |
from flask import Response, jsonify, make_response
@app.route('/')
def index():
data = {'message': 'ok'}
# return Response(response=jsonify(data), status=200)
return make_response(jsonify(data), 200) |
Merged
|
root@93442a991c37:/opt# mypy .
Success: no issues found in 14 source files
root@93442a991c37:/opt# cd ..
root@93442a991c37:/# mypy .
There are no .py[i] files in directory '.'
root@93442a991c37:/# mypy opt
Success: no issues found in 14 source files
root@93442a991c37:/# mypy opt/ --config-file opt/mypy.ini
Success: no issues found in 14 source files
root@93442a991c37:/# mypy opt/ --config-file opt/mypy.ini
opt/mock/my_class_test.py:7: error: Function is missing a type annotation
opt/mock/my_class_test.py:9: error: Function is missing a type annotation
opt/mock/my_class_test.py:13: error: Function is missing a return type annotation
opt/mock/my_class_test.py:24: error: Function is missing a return type annotation
Found 4 errors in 1 file (checked 14 source files) |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contents
The text was updated successfully, but these errors were encountered: