testing
unit vs integration
Unit-tests must be deterministics, fast and non IO-bound. In practive it involves heavy mocking.
Another drawback, because of the work implied when objects are refactored, unit-tests might be a barrier against refactoring/optimizing.
Full coverage via unit-tests is an overkill in most situations.
As unit-tests usually ignore private methods in objects, one can argue that implementation details should be ignored (thus unit-tests) and only results correctness is important to be tested (integration).
If it makes sense, especially in API context where input/output is limited, some applications have too much different states to be tested globally via integration tests only, then unit-tests would add value on specific parts.
python
pytest
coverage
(env) $ pip3 install pytest-cov
(env) $ python3 -m pytest -v --cov=./lib tests/unit/test_script.py
line_profiler
pip3 install line_profiler
On Notebook:
%load_ext line_profiler
def fn():
...
%lprun -f fn fn()
web
selenium
docs
pip3 install selenium
jsdom
Install
Firefox
wget https://github.com/mozilla/geckodriver/releases/download/<VERSION>/geckodriver-<VERSION>-linux64.tar.gz
ChromeDriver Chromium download page
Same standalone browser version must be installed before using chromedriver.
wget https://chromedirever.storage.googleapis.com/<VERSION>/chromedriver_linux64.zip
Edge
wget https://msedgedriver.azureedge.net/<VERSION>/edgedriver_linux64.zip
# Firefox
from selenium.webdriver.firefox.service import Service
from selenium import webdriver
service = Service(executable_path='/path/to/geckodriver')
driver = webdriver.Firefox(service=service)
driver.get('https://www.mozilla.org')
# Chrome
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
service = Service(executable_path='/path/to/chromedriver')
driver = webdriver.Chrome(service=service)
Usage
``` from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys
print(driver.current_url)
driver.find_element(By.ID, 'user_login').send_keys('user@test.com') ``̀