Skip to content

2022

pip upgrade all packages

Sometimes, we want to upgrade all the python packages installed, the following python script can help to upgrade all the packages installed.

Python
import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
for pkg_name in packages:
    call("pip install --upgrade " + pkg_name, shell=True)

If you want to upgrade a package with dependencies, then run the following command.

See doc https://pip.pypa.io/en/stable/development/architecture/upgrade-options/

Bash
pip install --upgrade --upgrade-strategy=eager <package name>

Python Unit Test Basic

pytest.fixture scope

Available scopes are function, class, module, and session. The default scope is function.

Python
@pytest.fixture(scope='function')
def test_function():
    pass

Mock

  1. Mock a class with attributes

    Python
    obj = Mock(spec=Class, attr=value)
    

go lang project mod operations

  1. Sync dependencies in the mod

    Bash
    go get ./...
    
  2. Update dependencies

    Bash
    go get -u ./...
    
  3. Force update a dependency to a branch or a commit

    Bash
    go get -v -u github.com/<org>/<repo>@<branch or commit>