Collection of Python scripts
- Python
OOP
& basic demo
Development
(ds_dash) yennanliu@yennanliu-MBP:~/utility_python(master⚡) » pytest -v tests
# ============================ test session starts =============================
# platform darwin -- Python 3.5.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /Users/yennanliu/anaconda3/envs/ds_dash/bin/python
# cachedir: .pytest_cache
# rootdir: /Users/yennanliu/utility_python
# plugins: celery-4.2.1
# collected 1 item
# tests/unit_test.py::CodeToTestTestCase::test_database_drop_table_call PASSED [100%]
# ========================== 1 passed in 0.05 seconds ==========================
Ref
-
Functional programming (fp)
VSObject-oriented programming (OOP)
-
Regular expression doc
-
Regular expression online playground
-
Regular expression tutorial
-
Python test tutorial
- https://realpython.com/tutorials/testing/
- Use a
decorator
: when all of the code in your test function body uses a mock. - Use a c
ontext manager
: when some of the code in your test function uses a mock and other code references the actual function. - Use a
patcher
: when you need to explicitly start and stop mocking a function across multiple tests (e.g. the setUp() and tearDown() functions in a test class).
-
Unit test mock DB func with python
- https://www.stevenmaude.co.uk/posts/how-to-use-mock-in-python-to-mock?fbclid=IwAR15w5IZesgbksFYkp_HBxMXRVk2ip1LMnZ6J3Jf4_LjXuaQLPzCNk1x_58
- https://stackoverflow.com/questions/58873971/python-mock-multiple-queries-in-a-function-using-pytest-mock?fbclid=IwAR3Ouw0im_iFT6PBIclw5lLwNXs3lCTfayQdmZdYfYEpoFyLDmzHVMnf6zQ
-
Python
Mock
library intro- https://realpython.com/python-mock-library/#patch
- https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.side_effect
- A
.return_value
defines what the method will return - A
.side_effect
defines what happens when you call the mocked function.
- A
-
Python
interface
intro -
pytest with fixture
- flake 8, PEP8
- pycharm integration
- integration test