1. Ned Batchelder
  2. coverage.py
  3. Issues
Issue #203 resolved

Duplicate filenames reported when filename contains uppercase letters on windows.

Thomas Maslach
created an issue

Our source code contains python files that have uppercase letters in the filenames. On windows, when running tests that utilize these source files, the coverage report is showing the files with uppercase letters twice in the list - once with the upper case letters, once in all lower case.

I have figured out why:

In data.py: It seems touch_file is called for all files. Passed into it is the filename that contains upper cased letters.

For files that are partly coveraged, we also call add_line_data. The filename passed into here is the canonical filename which is gotten from File.py, FileLocator.canonical_filename. This function calls os.path.normcase, which lowers the case on windows. Uh-oh! We don't do that when we call touch_file, so files show up in the report twice when they have uppercased letters..

How to fix? I'm not sure what the right solution is, but my guess is we should call the canonical_filename function before calling touch_file. This would be in control.py.

Let me know if you have any questions.. My fix is just a suggestion... Thanks!

Comments (13)

  1. Thomas Maslach reporter

    I have attached a zip file with a really simple example. I'm running pytest, however, and just run with the following arguments (in the same dir as the files): py.test testTest.py --cov .

    I realized while creating this simple example that the problem only shows up once I add the __init__.py file to the mix. At that point the coverage output goes from showing just testtestto showing SkippedTest, __init__, testTest, and testtest

  2. Thomas Maslach reporter

    I tried, but no success. I'm not able to get SkippedTest to show up in the list. I'm probably not use the right switch is my guess. I can only get testtest to show up. My guess is that I don't know the switch to get the touch_file command to execute, but that is only a guess..

  3. Thomas Maslach reporter

    Ned - figured it out. Please use the attached .coveragerc file as well. That is, drop into the same location as the other files. You'll need to change the path in the .coveragerc file to wherever you place the files. It should point to directory that the files are in.

    When you do this, you'll notice testTest and testtest are reported on.

    As a side note, I did find another issue along the same lines. It seems I can't use source and omit the way I would expect it to work. Using the same example, let's say I specify the [run] source=<path to my files>. Then, I specify omit=SkippedTest. It won't omit SkippedTest because source will override omit..

    What I have are a couple of py files in my package that don't run with the app (they are either experiments/developer demos). I want everything in the package included in coverage, except for these couple of files (ideally, I want them to show up in the list, but have all lines excluded from coverage). Is there a way to do this? I can create another issue for this, if you want, or maybe post this in the forums.. Thanks!

  4. Thomas Maslach reporter

    Ignore the second 2 paragraphs above for now.. I know how to do it through coverage now, I just need to figure out how to do it via pytest... However, the first 2 paragraphs are relevant to this bug..

  5. Log in to comment