Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tox + code coverage #150

Merged
merged 16 commits into from
Jan 31, 2020
Merged

Conversation

algattik
Copy link
Contributor

@algattik algattik commented Jan 24, 2020

Changes:

  • Allow developers to lint & test locally in a single command: streamlined use of flake8 and pytest within tox.
$ tox
python run-test-pre: PYTHONHASHSEED='1159078597'
python run-test: commands[0] | flake8 --output-file=lint-testresults.xml --format junit-xml
python run-test: commands[1] | pytest tests/unit --cov=code --cov-report=xml --junitxml=unit-testresults.xml
=========================================================================== test session starts ===========================================================================
...
tests/unit/code_test.py .                                                                                                                                           [ 20%]
tests/unit/data_test.py .
...                                                                                                                                        
---------- coverage: platform darwin, python 3.7.6-final-0 -----------
Coverage HTML written to dir htmlcov
Coverage XML written to file /Users/algattik/GitHub/MLOpsPython2/coverage.xml

====================================================================== 5 passed, 4 warnings in 6.34s ======================================================================
_________________________________________________________________________________ summary _________________________________________________________________________________
  python: commands succeeded
  congratulations :)
  • Added code coverage report. Required adapted pytest commandline (now in tox.ini) and installing .NET Core as for security reasons, the AzDO PublishCodeCoverageResults does not publish user-generated HTML reports anymore.
    image

  • Linting fixes in some .py scripts to avoid CI build failing.

  • Some simplifications in the build pipeline YAML.

commit 3ba351c
Author: Alexandre Gattiker <algattik@users.noreply.github.com>
Date:   Sat Jan 25 08:37:53 2020 +0100

    .

commit 5c3c3e0
Author: Alexandre Gattiker <algattik@users.noreply.github.com>
Date:   Sat Jan 25 07:58:50 2020 +0100

    .

commit 2a49221
Author: Alexandre Gattiker <algattik@users.noreply.github.com>
Date:   Sat Jan 25 07:24:37 2020 +0100

    .
Merge remote-tracking branch 'upstream/master' into algattik/code-coverage
@algattik algattik marked this pull request as ready for review January 25, 2020 15:51
@algattik algattik requested a review from eedorenko January 25, 2020 15:51
@eedorenko eedorenko self-assigned this Jan 27, 2020
Install the required Python modules in your virtual environment.

```
pip install -r environment_setup/build-image/requirements.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requirements.txt is in environment_setup folder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "pip install -r environment_setup/requirements.txt"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, apologies

# Install Python modules
COPY requirements.txt /setup/
RUN pip install --upgrade -r /setup/requirements.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reducing the number of image layers by combining RUN commands.
"squash" option is still experimental.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to reduce RUN steps

@eedorenko
Copy link
Contributor

The build fails with "No code coverage results were found to publish."

@algattik
Copy link
Contributor Author

The build fails with "No code coverage results were found to publish."

The mlopspython image must first be updated as there are new dependencies.
Here is a sample build (on a derived branch which only replaces the mlopspython container with a privately build container from the Dockerfile):
https://dev.azure.com/algattik/MLOpsPython/_build/results?buildId=300&view=codecoverage-tab

@algattik
Copy link
Contributor Author

Updated with changes from master

@algattik algattik requested a review from eedorenko January 30, 2020 05:39
# Install dotnet runtime used to generate code coverage report
RUN curl -O https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& apt-get update && apt-get install -y dotnet-runtime-3.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need dotnet-runtime-3.1? I assume code coverage will still show up in Azure DevOps, but we'll just get the warning of no auto-generated html reports, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without dotnet runtime we only get the report as an artifact.

With dotnet runtime we get an an embedded HTML report

image

this can be achieved by:

  1. Adding dotnet runtime to mlopsython container, is an additional 104 MB installation.
  2. install dotnet at pipeline execution time.

Given the impact of 1 or 2 in terms of build time and the limited benefit of the embedded report, I will update the PR to go for neither option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea would be to add 2. commented out in the pipeline if people want to enable the code coverage html report

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Note that we will see this warning:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. There is no update to the Dockerfile anymore, but the mlopspython image must still be rebuilt because of updates to requirements.txt.
I tested installing dotnet core but coverage report generation then fails with a missing libicu library, and sudo is not available to install it. I suggest investigating this at a later point.

Copy link
Contributor

@eedorenko eedorenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

David Tesar's comment:
"Do we really need dotnet-runtime-3.1? I assume code coverage will still show up in Azure DevOps, but we'll just get the warning of no auto-generated html reports, no?"

@algattik
Copy link
Contributor Author

Implemented change due to PR #162, that breaks compatibility with tox virtual environments.

dc00144: Run linter and unit tests in the system python (i.e. in conda environment). This also makes things faster as tox does not have to build a venv.

@algattik
Copy link
Contributor Author

After we merge #158 we should be able to add instructions for enabling report generation:

  • Add icu to CI conda environment
  • Add dotnet core install task in Build pipeline

@eedorenko eedorenko merged commit e0e6d22 into microsoft:master Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants