2

When I run the command coverage report -m after running coverage run main.py any of the lines in the methods that I have test are covered, I using a context.py file and I have the following project structure

my_project
├── service
│   ├── __init__.py        
│   └── setThings.py
└── test
    ├── context.py 
    ├── __init__.py         
    └── test_setThings.py

this is the content of my context.py

import sys
import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import service
from service import setThings

This is my service setThings.py

from jinja2 import Environment, FileSystemLoader

def check_if_json_property_is_null(json_property):
    if(json_property != ""):
        return json_property
    else:
        return "&nbsp"

and this is my test file

import unittest
import json
from collections import namedtuple

from .context import setThings

class Test_SetThings(unittest.TestCase):

    def test_given_none_property_when_checking_if_none_return_empty(self):
        #ASSERT
        self.assertEqual("&nbsp", setThings.check_if_json_property_is_null(""))

if __name__ == '__main__':
    unittest.main()

So after I run coverage report -m it says that the lines inside my service methods are not covered, I'm using coverage==4.5.3 in my requirements file,

Also I'm running all the commands from the project root

2
  • We usually use coverage to measure the code coverage of your library (here service, but not to measure the coverage of your test: it's a non-sense. Commented Nov 19, 2019 at 21:06
  • I edited my question I was referring to the lines of my service, the lines of my service are not being covered Commented Nov 20, 2019 at 16:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.