Molecule, Tox, and code coverage

415 views
Skip to first unread message

dewey....@gmail.com

unread,
Jul 4, 2018, 4:19:51 PM7/4/18
to molecule-users
I've recently started using Molecule and really like what I see. I noticed that in the documentation Tox was used and mentioned in the testing page: https://molecule.readthedocs.io/en/latest/testing.html
Additionally in that page coverage was mentioned as something that Tox would do. I was wondering if anybody has used Tox to report code coverage for the tests molecule kicks off and how they did it. It's not clear to me how I could get coverage reports or if it is even possible with Molecule sitting the middle.

Thanks!

John Dewey

unread,
Jul 5, 2018, 2:03:42 PM7/5/18
to dewey....@gmail.com, molecule-users
Tox executes pytest

    unit: py.test -vv --cov-report=term-missing --cov={toxinidir}/molecule/ --no-cov-on-fail {posargs}

The coverage occurs via the `—cov` flag and the pytest-cov plugin.


Once tox has completed you can execute `coverage html` in your terminal to generate a html file with the coverage information you are probably looking for.

John
--
You received this message because you are subscribed to the Google Groups "molecule-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to molecule-user...@googlegroups.com.
To post to this group, send email to molecul...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/molecule-users/bac9fe92-6a2a-468a-99ba-34056eb20d27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dewey....@gmail.com

unread,
Jul 5, 2018, 9:02:43 PM7/5/18
to molecule-users
I ran tox, but in addition to not seeing any output from tox indicating coverage is being done (I am assuming there should be some output when tox runs that) I am also not getting any report back when I run the coverage html or even coverage report. Both commands return "No data to report."

Dewey

John Dewey

unread,
Jul 5, 2018, 9:08:22 PM7/5/18
to dewey....@gmail.com, molecule-users
Need more details.  Tox outputs data.

dewey....@gmail.com

unread,
Jul 5, 2018, 9:29:39 PM7/5/18
to molecule-users
My tox.ini:
[tox]
minversion = 1.8
envlist = py36
skipsdist = true

[testenv]
passenv = *
commands =
    molecule test
deps =
    -rrequirements.txt
    ansible22: ansible==2.2.0.0


-----------------------------------------------------------------------------

My tox output appears to have the following:
create
installdeps
installed (coverage is not one of them)
runtests: PYTHONHASHSEED
runtests: commands[0] | molecule test
Molecule Output including the test session Molecule itself runs
Summary indicating the commands succeeded
congratulations :)

Currently the only tests written are those in my molecule/default/tests directory.


Thanks,
Dewey

John Dewey

unread,
Jul 6, 2018, 2:54:20 PM7/6/18
to dewey....@gmail.com, molecule-users
I must have misunderstood you.  I thought you were talking about running Molecule’s tox.ini [1], not running your own role in tox.  Molecule isn’t a unit test framework, it has no mechanism for creating code coverage for you role.




John

dewey....@gmail.com

unread,
Jul 6, 2018, 3:32:29 PM7/6/18
to molecule-users
So is this page: https://molecule.readthedocs.io/en/latest/testing.html in the docs in regards to testing molecule itself, for molelcule development? It mentioned code coverage but makes no mention of it being specific to molecule development. I may have misunderstood what the page was for/aiming to provide to readers.

Daniel

John Dewey

unread,
Jul 7, 2018, 1:24:42 AM7/7/18
to dewey....@gmail.com, molecule-users
It’s meant for molecule developers.
Reply all
Reply to author
Forward
0 new messages