title: Python coverage running the tests in local against the same service in docker
body: <p>I have a service code in python. For the functional tests, I run the tests in local against the same service built in a docker container because I want to test a REST API call or a Rabbitmq message, etc.</p>
  
  <p><strong>Step 1.</strong></p>
  
  <pre><code>$ docker-compose.yml
  
    third_party_service_1:
    ...
  
    third_party_service_2:
    ...
  
  
    my_service:
      build:
        context: .
    ...
  </code></pre>
  
  <p><strong>Step 2.</strong></p>
  
  <pre><code>$ docker-compose up --build -d
  </code></pre>
  
  <p><strong>Step 3.</strong></p>
  
  <pre><code>$ coverage run -m pytest tests/functional
  </code></pre>
  
  <p>Obviously, the coverage does not work because the code in the docker image is the code copied from the local. </p>
  
  <p>Is there a way to collect the coverage in this situation?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT:</strong> 
  I mean, I don't get the coverage from the functional tests because the code that is running because of the tests, is not the local code where I run the coverage and pytest commands. The functional tests know that they have to attack the docker image that I built. So, for the coverage, it is like you're launching the tests against a third party service, because it is not able to know which code is executed.</p>
  
  <pre><code>---------------------
  |    LOCAL          |
  | my_service code   |
  |                   |
  | I run:            |
  | $ coverage run... |
  ---------------------
  
  ---------------------
  |    DOCKER         |
  | my_service code   |
  |  (up&amp;running)     |
  ---------------------
  </code></pre>