我有两个测试文件。
一个是标准的测试案例。另一个有硒测试。我有一个docker-compose文件设置来运行硒测试及其相关服务。
测试在bitbucket管道中运行。首先,它使用标准TestCases运行测试。然后,在下一步中,它使用docker-compose来运行包含硒的测试,因为它需要编写来设置硒服务。
我遇到的问题是,在没有任何硒容器运行的情况下,尝试在第一步中运行硒测试。
我在用于第一部分测试的Django设置文件中输入了此代码:
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'
]
,然后在我的设置中进行第二次:
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'
]
如您所见,我要排除硒测试的第一部分,而将硒测试用于第二部分。但是即使我在else_args中排除了它,它仍然在第一部分中运行硒测试。
这是我的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是第一部分,它具有排除硒测试文件的设置。
Dockerfile.test和docker-compose.test.yml用于第二部分,并且不排除硒测试文件。
我的配置/设置有意义吗?我是否可以正确排除nas_args中的文件?因为正如我所说的,它不应该在第一部分中运行硒测试。
任何输入将不胜感激。
谢谢
编辑:
现在我的NOSE_ARGS:
不忽略任何测试:
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'
]
要排除硒测试:
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'
]
答案 0 :(得分:1)
基于https://nose.readthedocs.io/en/latest/usage.html#cmdoption-e --exclude
的参数应为正则表达式。
您尝试过类似--exclude=selenium
的事情吗?
编辑
说在项目中有一个测试tests/integration/test_integration.py
要忽略。正在运行
nosetests -v --exclude=integration
或
nosetests -v --ignore-files=test_integration.py
可以解决问题(即执行除test_integration.py
中的测试以外的所有测试)。