2

I have two test files.

One is standard TestCases. The other has selenium tests in it. I have a docker-compose file setup to run the selenium tests with their associated services.

The tests run in bitbucket-pipelines. First it runs the test with the standard TestCases. Then in the next step it uses docker-compose to run the tests that include selenium since it needs compose to set up the selenium services.

The issue I'm having is it's trying to run the selenium tests during the first step when there isn't any selenium containers running.

I entered this in my Django settings file used for the first testing part:

NOSE_ARGS = [
    '--exclude=(__init__.py)',
    '--exclude=(../tests/selenium_tests.py)',
    '--exclude=(selenium_tests.py)',
    '--with-coverage',
    '--cover-package=sasite',
    '--with-xunit',
    '--xunit-file=test-results/nose/noseresults.xml',
    '--verbosity=3',
    '--cover-xml',
    '--cover-xml-file=test-results/nose/noseresults.xml',
    '--id-file=test-results/nose/noseids'
]

and in my settings for the second:

NOSE_ARGS = [
    '--exclude=(__init__.py)',
    '--with-coverage',
    '--cover-package=sasite',
    '--with-xunit',
    '--xunit-file=test-results/nose/noseresults.xml',
    '--verbosity=3',
    '--cover-xml',
    '--cover-xml-file=test-results/nose/noseresults.xml',
    '--id-file=test-results/nose/noseids'
]

As you can see, I want to exclude the selenium tests for the first part, and use them for the second. But even with my exclude in nose_args it still runs the selenium tests in the first part.

Here is my bitbucket-pipelines.yml:

   prod-final:
      - step:
          name: Build image, run tests, and push to Docker Hub
          caches:
            - docker
          services:
            - docker
          script:
            # Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment variables in repository settings
            - export DOCKER_HUB_USERNAME=X
            - export DOCKER_HUB_PASSWORD=XXX

            # build the Docker image (this will use the Dockerfile in the root of the repo)
            - docker build -t meleiyu/sawebsite-redesign -f Dockerfile.imagetest .
            # run tests
            - docker run meleiyu/sawebsite-redesign
            # tag Docker image
            - docker tag meleiyu/sawebsite-redesign meleiyu/sawebsite-redesign:latest
            # authenticate with the Docker Hub registry
            - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
            # push the new Docker image to the Docker registry
            - docker push meleiyu/sawebsite-redesign:latest      
      - step:
          name: Run second level of testing with BrowserStack
          image: docker:stable
          trigger: manual          
          caches:
            - docker
          services:
            - docker
          script:
            # Test production setup with compose
            - apk add --no-cache py-pip bash
            - pip install --no-cache docker-compose
            - docker-compose -f docker-compose.test.yml up -d --build --exit-code-from app
      - step:
          # set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION as environment variables
          name: Deploy to AWS
          deployment: staging   # set to test, staging or production
          trigger: manual  # uncomment to have a manual step
          image: atlassian/pipelines-awscli
          script:
            - aws deploy push --application-name sawebsite-redesign --s3-location s3://<S3 bucket>/<s3-key> --ignore-hidden-files
            - aws deploy create-deployment --application-name sawebsite-redesign --s3-location bucket=<s3-bucket>,key=<s3-key>,bundleType=zip --deployment-group-name <deployment-group>

definitions:
  services:
    docker:
      memory: 3072

Dockerfile.imagetest is for the first part, and has the settings to exclude selenium tests file.

Dockerfile.test and docker-compose.test.yml are for the second part and don't exclude the selenium tests file.

Does my config/setup make sense?? Am I excluding the files correctly in nose_args? Because as I said it's running the selenium tests in part one when it shouldn't be doing so.

Any input would be appreciated.

Thanks

EDIT:

My NOSE_ARGS now:

To not ignore any tests:

NOSE_ARGS = [
    '--exclude=(__init__.py)',
    '--with-coverage',
    '--cover-package=sasite',
    '--with-xunit',
    '--xunit-file=test-results/nose/noseresults.xml',
    '--verbosity=3',
    '--cover-xml',
    '--cover-xml-file=test-results/nose/noseresults.xml',
    '--id-file=test-results/nose/noseids'
]

To exclude selenium tests:

NOSE_ARGS = [
    '--exclude=(__init__.py)',
    '--exclude=(../tests/selenium_tests.py)',
    '--exclude=(selenium_tests.py)',
    '--ignore=(selenium_tests.py)',
    '--ignore=(../tests/selenium_tests.py)',
    '--ignore-files=../tests/selenium_tests.py',    
    '--ignore-files=selenium_tests.py',    
    '--with-coverage',
    '--cover-package=sasite',
    '--with-xunit',
    '--xunit-file=test-results/nose/noseresults.xml',
    '--verbosity=3',
    '--cover-xml',
    '--cover-xml-file=test-results/nose/noseresults.xml',
    '--id-file=test-results/nose/noseids'
]
ss7
  • 2,902
  • 7
  • 41
  • 90

1 Answers1

1

Based on https://nose.readthedocs.io/en/latest/usage.html#cmdoption-e --exclude argument should be a regex.

Did you try something like --exclude=selenium?

EDIT

Say there's a test tests/integration/test_integration.py in the project which you want to ignore. Running

nosetests -v --exclude=integration

or

nosetests -v --ignore-files=test_integration.py

does the trick (i.e. all tests but those in test_integration.py are executed).

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
  • `'--exclude=(__init__.py)',` was in there already as a functioning example. – ss7 Dec 15 '18 at 21:03
  • so instead of `'--exclude=(../tests/selenium_tests.py)',` use something like `--exclude='*selenium*',`?? – ss7 Dec 15 '18 at 21:04
  • 1
    Yes, or try excluding files: https://nose.readthedocs.io/en/latest/usage.html#cmdoption-i. – Dušan Maďar Dec 15 '18 at 21:05
  • I tried that too but had trouble, Coudl you give me an example for excluding or ignoring the file selenium_tests.py in the /tests/ directory? – ss7 Dec 15 '18 at 21:06
  • 1
    I tried a couple of things locally and updated the answer. – Dušan Maďar Dec 15 '18 at 21:24
  • I'll give the ignore a shot in my settings for NOSE_ARGS. As for calling nosetests directly, I don't even do that. I call python manage.py test and my testrunner is set to nose in the settings. Is there still a work around? – ss7 Dec 15 '18 at 21:26
  • 1
    Right, that's a different story then. Take a look at https://stackoverflow.com/questions/28229864/django-manage-py-is-it-possible-to-pass-command-line-argument-for-unit-testin. – Dušan Maďar Dec 15 '18 at 21:30
  • Not sure how it's different. I added it to my NOSE_ARGS in settings and it seems to have worked. – ss7 Dec 15 '18 at 21:32
  • Thought I cannot seem to get clarification between exclude, ignore, and ignore files as well as their syntaxes. – ss7 Dec 15 '18 at 21:32