Custom Search
Showing posts with label Tox. Show all posts
Showing posts with label Tox. Show all posts

Monday, December 8, 2014

Setting Up OpenStack Python Client Development Environment

1)
Clone the Project

#git clone https://github.com/openstack/python-keystoneclient.git

2)
Goto cloned directory

#cd python-keystoneclient



3)
Setup the Environment


3,a)
With run_tests.sh

#./run_tests.sh

OR

3,b)
With tox

#sudo pip install tox
#tox

4)
Run the client commands


4,a)
With run_tests.sh Environment


4,a,a)Goto cloned directory
#cd python-keystoneclient

4,a,b)
Create a script named "keystone" with following statements in cloned directory.
#vim keystone

#!/usr/bin/python
# PBR Generated from 'console_scripts'
import sys
from keystoneclient.shell import main
if __name__ == "__main__":
    sys.exit(main())


4,a,c)
Run the keystone client commands from run_tests.sh Environment
#source .venv/bin/activate
#.venv/bin/python keystone tenant-list
#.venv/bin/python keystone user-list


OR

4,b)
With Tox Environment

4,b,a)
Goto cloned directory
#cd python-keystoneclient

4,b,b)
Create a script named "keystone" with following statements in cloned directory.
#vim keystone

#!/usr/bin/python
# PBR Generated from 'console_scripts'
import sys
from keystoneclient.shell import main
if __name__ == "__main__":
    sys.exit(main())


4,b,c)
Run the keystone client commands from Tox Environment
#source .tox/py27/bin/activate
#.tox/py27/bin/python keystone tenant-list
#.tox/py27/bin/python keystone user-list


5)
Run the Tests


5,a)
With run_tests.sh
#./run_tests.sh --debug keystoneclient.tests.v2_0.test_tenants.TenantTests.test_list

##Only pep8 test
#./run_tests.sh --debug --pep8 keystoneclient.tests.v2_0.test_tenants

##manual pep8 test with the wrapper flake8
#source .venv/bin/activate
#flake8 keystoneclient/tests/v2_0/test_tenants.py


OR

5,b)
With tox


* Deactivate virtualenv (Important), then run tox command , otherwise tox command will try to recreate the virtualenv from scratch
#deactivate

*UnitTest
#tox -e py27 -- keystoneclient.tests.v2_0.test_tenants.TenantTests.test_list
#tox -e py27 -- keystoneclient.tests.v2_0.test_tenants
#tox -e py27

*pep8 test
#tox -e pep8 -- keystoneclient.tests.v2_0.test_tenants
#tox -e pep8

http://fosshelp.blogspot.in/2014/11/openstack-unit-testing-tox-runtestssh.html







Sunday, November 30, 2014

OpenStack Unit Testing With Tox, run_tests.sh and testr

OpenStack python-neutronclient Unit Testing With Tox, run_tests.sh and testr

https://github.com/openstack/python-neutronclient/

1)

Clone python-neutronclient
#git clone https://github.com/openstack/python-neutronclient.git

2)
Some useful links
https://github.com/openstack/python-neutronclient/blob/master/HACKING.rst

http://docs.openstack.org/developer/hacking/ <=== IMP

3)
Tox and testr configs

https://wiki.openstack.org/wiki/Testr

https://github.com/openstack/python-neutronclient/blob/master/.testr.conf

https://github.com/openstack/python-neutronclient/blob/master/tox.ini

https://github.com/openstack/python-neutronclient/blob/master/test-requirements.txt


https://github.com/openstack/python-neutronclient/blob/master/requirements.txt

4)
What is testr, tox and run_tests.sh ??


a)
Test repository (testr) is a small application for tracking test results.
testr is configured via the ‘.testr.conf’ file which needs to be in the same directory that testr is run from.

http://testrepository.readthedocs.org/en/latest/MANUAL.html

b)
Tox aims to automate and standardize testing in Python.
Tox is a generic virtualenv management and test command line tool you can use for:
* checking your package installs correctly with different Python versions and interpreters.
* Running your tests in each of the environments, configuring your test tool of choice.
* Acting as a frontend to Continuous Integration servers, greatly reducing boilerplate and merging CI and shell-based testing.

Install tox "pip install tox" and put basic information about your project and the test environments you want your project to run in into a tox.ini file.You can also try generating a tox.ini file automatically, by running tox-quickstart and then answering a few simple questions.

http://tox.readthedocs.org/en/latest/
http://tox.readthedocs.org/en/latest/examples.html

c)
Actually "tox" and "run_tests.sh" are wrappers to use "testr".

5)
Install and run tox to setup test env and test your project

#cd python-neutronclient
#sudo pip install tox


To install and setup all environments defined in the "tox.ini" file.
#tox

* "tox" command will read "python-neutronclient/tox.ini" and setup test env and test the project.
* "tox" command also read "python-neutronclient/test-requirements.txt" to setup test env, see "tox.ini" file.
* This "tox" command will creates hidden files like ".testrepository" and ".tox".
* List all environment folders in the ".tox" hidden folder "#ls .tox"
* This command setup all environments defined in the "tox.ini" file and install all dependencies defined in the "requirements.txt" and "test-requirements.txt".
* https://wiki.openstack.org/wiki/Testr

6)
To install and setup python 2.7 (py27) envirtonment

#tox -epy27
* Don't manually activate virtualenv and execute this "tox" command, since it recreate the virtualenv at that case.

OR

Use "-r" option to recreate the environment from scratch and install all dependencies defined in the "requirements.txt" and "test-requirements.txt".
##tox -epy27 -r

* Under ".tox" hidden folder, you can see the environment directory "py27". Also check "tox.ini" file for configuration.
* Check the log file "#tail -f .tox/py27/log/py27-1.log" in the hidden dir to see what happens during the environment setup.

7)
List all test environments

#tox -l
py26
py27
py33
pypy
pep8

8)
show configuration information for all environments

#tox --showconfig
* This command read from "tox.ini" file.

9)
How can I run just one test ??.


Method-1):

Using Tox
a)
Deactivate virtualenv

b)
Run Test
#tox -epy27 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON.test_create_network
#tox -epy27 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON
#tox -epy27 -- neutronclient.tests.unit.test_cli20_network
#tox -epy27 -- neutronclient.tests
#tox -epy27


* Don't manually activate virtualenv and execute this "tox" command, since it recreate the virtualenv at that case.

Method-2):


Using testr
a)
Activate virtualenv
#source .tox/py27/bin/activate

b)
Run Test
#testr run neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON.test_create_network
#testr run neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON
#testr run neutronclient.tests.unit.test_cli20_network
#testr run neutronclient.tests
#testr run


c)
Run parallel Test
#testr run --parallel neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON.test_create_network
#testr run --parallel neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON
#testr run --parallel neutronclient.tests.unit.test_cli20_network
#testr run --parallel neutronclient.tests
#testr run --parallel


10)
Run pep8 test


a)
Using Tox


* Deactivate virtualenv

* Run only pep8 Test
#tox -e pep8 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON.test_create_network
#tox -e pep8 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON
#tox -e pep8 -- neutronclient.tests.unit.test_cli20_network
#tox -e pep8 -- neutronclient.tests
#tox -e pep8


* Run py27 and pep8 Test
#tox -e py27,pep8 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON.test_create_network
#tox -e py27,pep8 -- neutronclient.tests.unit.test_cli20_network.CLITestV20NetworkJSON
#tox -e py27,pep8 -- neutronclient.tests.unit.test_cli20_network
#tox -e py27,pep8 -- neutronclient.tests
#tox -e py27,pep8


http://docs.openstack.org/developer/ceilometer/contributing/source.html

b)
Using flake8


* Activate virtualenv
#source .tox/py27/bin/activate
* Run pep8 test
#flake8

11)
testr helps


#testr commands
#testr help run


12)
Run only the tests in the CLITestV20NetworkJSON class
#tox -epy27 -- '(CLITestV20NetworkJSON)'
Run only the tests in the CLITestV20NetworkJSON and CLITestV20FloatingIpsJSON classes
#tox -epy27 -- '(CLITestV20NetworkJSON|CLITestV20FloatingIpsJSON)'
Run only the test "test_create_network" in the CLITestV20NetworkJSON class
#tox -epy27 -- '(CLITestV20NetworkJSON.test_create_network)'
Run only the tests "test_create_network" and "test_create_floatingip" in the CLITestV20NetworkJSON and CLITestV20FloatingIpsJSON classes
#tox -epy27 -- '(CLITestV20NetworkJSON.test_create_network|CLITestV20FloatingIpsJSON.test_create_floatingip)'

13)
run only particular test of python-tackerclient project

$ python -m testtools.run tackerclient.tests.unit.test_validators.ValidatorTest

$ python -m testtools.run tackerclient.tests.unit.test_validators.ValidatorTest.test_validate_ip_subnet

14)