#415 more robust ./run_tests.sh
Merged a year ago by praiskup. Opened a year ago by praiskup.
copr/ praiskup/copr fix-frontend-testsuite  into  master

file modified
+1 -7

@@ -265,13 +265,7 @@ 

  

  %check

  %if %{with check}

-     pushd coprs_frontend

-     REDIS_PORT=7777

-     redis-server --port $REDIS_PORT & #&> _redis.log &

-     rm -rf /tmp/copr.db /tmp/whooshee || :

-     COPR_CONFIG="$(pwd)/config/copr_unit_test.conf" ./manage.py test

-     redis-cli -p $REDIS_PORT shutdown

-     popd

+ ./run_tests.sh

  %endif

  

  %pre

@@ -25,17 +25,34 @@ 

  

  class TestCommand(Command):

  

-     def run(self, test_args):

+     def run(self, coverage, test_args):

          os.environ["COPRS_ENVIRON_UNITTEST"] = "1"

          if not (("COPR_CONFIG" in os.environ) and os.environ["COPR_CONFIG"]):

              os.environ["COPR_CONFIG"] = "/etc/copr/copr_unit_test.conf"

-         os.environ["PYTHONPATH"] = "."

-         return subprocess.call(["/usr/bin/python3", "-m", "pytest"] + (test_args or []))

+ 

+         if 'PYTHONPATH' in os.environ:

+             os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + ':.'

+         else:

+             os.environ['PYTHONPATH'] = '.'

+ 

+         additional_args = []

+ 

+         if coverage:

+             additional_args.extend([

+                 '--cov-report', 'term-missing', '--cov', 'coprs'

+             ])

+ 

+         return subprocess.call(["/usr/bin/python3", "-m", "pytest"] + additional_args)

  

      option_list = (

          Option("-a",

                 dest="test_args",

                 nargs=argparse.REMAINDER),

+         Option("--coverage",

+                dest="coverage",

+                required=False,

+                action='store_true',

+                default=False),

      )

  

  

file modified
+15 -7

@@ -1,13 +1,21 @@ 

- #!/bin/sh

+ #! /bin/bash

  

- REDIS_PORT=7777

+ set -x

+ set -e

  

+ REDIS_PORT=7777

  redis-server --port $REDIS_PORT &> _redis.log &

  

- path="${1:-tests}"

+ cleanup ()

+ {

+     redis-cli -p "$REDIS_PORT" shutdown

+     wait

+ }

+ trap cleanup EXIT

  

- cd coprs_frontend

- COPR_CONFIG="$(pwd)/config/copr_unit_test.conf" python3 -B -m pytest -s $path # \

-      #--cov-report term-missing --cov coprs $@

+ common_path=$(readlink -f ../common)

+ export PYTHONPATH="${PYTHONPATH+$PYTHONPATH:}$common_path"

+ export COPR_CONFIG="$(pwd)/coprs_frontend/config/copr_unit_test.conf"

  

- kill %1

+ cd coprs_frontend

+ ./manage.py test "$@"

  • reuse it in copr-frontend.spec
  • add --coverage option
  • wait till redis shuts down
  • do 'set -e' to fail asap, and 'set -x' to see logs
  • install 'cleanup' trap to always kill redis
  • put copr_common on PYTHONPATH

rebased onto fadeac49a58f4b302e4030a37667ebb50b8d61eb

a year ago

What is wrong with: redis-cli -p $REDIS_PORT shutdown ?

Can you call ./manage.py test .... instead of python3 -m pytest ...?

Can you pushd/popd so we end up in the same directory when script was executed?

I don't know, I'll try to find the reasons from git-log.

That would be a different patch; but I'm neither sure whether this is a good idea.

Script can not change global pwd, so it doesn't affect the state "after script was executed". But I'll use pushd.

rebased onto 609aee7733edaefea0e8ffee4828dc624bc22ae6

a year ago

rebased onto 07680c90a972b41fb73ab5d5feb2461375cc847e

a year ago

PTAL, I updated the ./manage.py test logic to accept --coverage option, and fixed ./run_tests.sh to execute ./manage.py test. Thanks for pointing this out.

rebased onto 788d2a5cb2f13930935768dd32c8e6bd29bde80d

a year ago

rebased onto 1a8162c37c24e2e77050505fc68688ea7b40e9f3

a year ago

rebased onto 1467614

a year ago

Pull-Request has been merged by praiskup

a year ago