0421730a73fed1a2f7c88a9e26f9d08a4e3ed17d
[functest.git] / run_unit_tests.sh
1 #!/bin/bash
2 set -o errexit
3 set -o pipefail
4
5 function clean_results_dir {
6     if [ -d "/home/opnfv/functest/results" ]
7     then
8         sudo rm -rf /home/opnfv/functest/results
9     fi
10 }
11
12 # ******************************
13 # prepare the env for the tests
14 # ******************************
15 # clean useless results dir
16 # should be done at the end
17 # but in case of crash during unit test
18 # clean it anyway
19 clean_results_dir
20
21 # TODO clean that...
22 # Create log dir if needed
23 # log shall be disabled during unit tests
24 # fix to be done in Logger
25 echo "Create dummy log file...."
26 sudo mkdir -p /home/opnfv/functest/results/odl
27 sudo touch /home/opnfv/functest/results/functest.log
28 sudo touch /home/opnfv/functest/results/odl/stdout.txt
29 sudo chmod -Rf a+rw /home/opnfv
30
31 # Either Workspace is set (CI)
32 if [ -z $WORKSPACE ]
33 then
34     WORKSPACE="."
35 fi
36
37
38 # ***************
39 # Run unit tests
40 # ***************
41 echo "Running unit tests..."
42
43 # start vitual env
44 virtualenv $WORKSPACE/functest_venv
45 source $WORKSPACE/functest_venv/bin/activate
46
47 # install python packages
48 sudo apt-get install -y build-essential python-dev python-pip
49 pip install --upgrade pip
50 pip install -r $WORKSPACE/test-requirements.txt
51 pip install $WORKSPACE
52
53 export CONFIG_FUNCTEST_YAML=$(pwd)/functest/ci/config_functest.yaml
54 # unit tests
55 # TODO: remove cover-erase
56 # To be deleted when all functest packages will be listed
57 nosetests --with-xunit \
58          --with-coverage \
59          --cover-erase \
60          --cover-tests \
61          --cover-package=functest.core.testcase_base \
62          --cover-package=functest.opnfv_tests.sdn.odl.odl \
63          --cover-package=functest.utils \
64          --cover-xml \
65          --cover-html \
66          functest/tests/unit
67 rc=$?
68
69 deactivate
70
71 # *******
72 # clean
73 # *******
74 # Clean useless logs
75 clean_results_dir
76
77 exit $rc