I want to run automated test cases against my Python Azure Functions and I want to do it in the same environment as what my actual API runs in. Thus, I want to do the testing within the Docker container. I haven't been able to find much info about this online.
My problem with what I have right now is that when I use
docker run $(imageRepository):$(tag) pytest .
it starts the API within my Azure Pipeline. Then it doesn't run the pytest command because that terminal is now running the local API. Is there any other way to test the API within the container within Azure Pipelines?
.yml pipeline file
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
name: $(name)
steps:
- checkout: self
displayName: Checkout
- task: Docker@2
displayName: Build the Docker image
inputs:
command: build
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
tags: |
$(tag)
- script: |
docker run $(imageRepository):$(tag) pytest .
displayName: 'Run Tests'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/report.xml'
condition: succeededOrFailed()
- task: Docker@2
displayName: Push the Docker image
inputs:
command: push
repository: $(imageRepository)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
condition: succeeded()
- task: AzureFunctionAppContainer@1
inputs:
azureSubscription: '$(azureSubscription)'
appName: '$(appName)'
imageName: '$(containerRegistry)/$(imageRepository):$(tag)'
condition: succeeded()
This is what I see at the Run Tests step, it starts the API and then it will just sit on this step because now the API is running.
Also, I'm following this doc and I did see this as well Stack Overflow post.
