Search in this blog

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, July 5, 2017

if...elif...else in Python


That’s the difference in Python between an if...elif...else and a series of ifs:
if a:
    do this
elif b:
    do that
elif c:
    do something else
else:
    print "none of the above"
is equivalent to (exactly the same as) this:
if a:
    do this
if (not a) and b:
    do that
if (not a) and (not b) and c:
    do something else
if (not a) and (not b) and (not c):
    print "none of the above"
As you can see, the elif...else notation allows you to write the same logic (the same control flow) without repeating the a condition over and over again.

Copied from here: https://www.codecademy.com/en/forum_questions/51684a3d4ce76309b4001b9c

Friday, January 6, 2017

How to create and manage python virtualenv?

Create, activate and deactivate virtualenv
cd my_project_folder

virtualenv .venv
. .venv/bin/activate

deactivate

Tuesday, December 27, 2016

Run a single python test with tox

This is the hint how to run a single or several specific functional and unit tests in python projects with tox.

Tox environment `functional`:

Run tests by the template of their name:
tox -e functional test_node_list

Run single test specifying full path:
tox -e ironicclient.tests.functional.osc.v1.test_baremetal_node_basic.BaremetalNodeTests.test_list

Run class of tests:
tox -e functional BaremetalNodeTests

Run specific test from class (including those under @ddt):
tox -e functional BaremetalNodeTests.test_delete

Unit tests (py27 for example):

Run several matching tests:
tox -e py27 do_port_show

Run single specific test from specified class:
tox -e py27 PortShellTest.test_do_port_show_invalid_fields