coverage 3.7.1 ignores --rcfile option

Issue #335 invalid
Inyeol Lee
created an issue

OSX 10.10, python 3.4.2 and coverage 3.7.1 via MacPort.

If I put coverage option to ./.coveragerc, it works. If I rename the config file and use --rcfile=renamed_file, then coverage ignores config file. If I point to non-existing rcfile, coverage still doesn't complain.

Looks like coverage only checks .coveragerc file in current dir and ignores --rcfile option.

Comments (4)

  1. Ned Batchelder repo owner

    A non-existent config file is silently ignored, perhaps that should be changed. We don't want to complain if the default .coveragerc file doesn't exist, but if you name a non-existent file on the command line, you should get an error. I've created issue #343 for that problem.

    But I see other-named config files being read just fine.

  2. Praveen Shirali

    OSX 10.9 -- Python 2.7 -- Coverage 3.7.1

    I thought I encountered the same behaviour mentioned above. However, this doesn't seem to be an issue with Coverage. I'm sharing my notes to benefit those who'd land here in future.

    If you have two files .coveragerc and .coveragerc_alpha co-exsting in the same folder, and you'd like to use .coveragerc_alpha, the --rcfile=.coveragerc_alpha must be specified explicitly in all commands.

    Example:

    1. coverage run --rcfile=".coveragerc_alpha" <...>
    
    This generates a `.coverage` file in the local folder with the coverage data
    
    2. coverage report --rcfile=".coveragerc_alpha"
    
    This uses the `.coverage` local file to display the coverage report as expected.
    

    At this point, we'd have three files, which are:

    .coverage                < coverage output which was generated using .coveragerc_alpha
    .coveragerc              < original coveragerc file
    .coveragerc_alpha        < alternate coveragerc file which was used for the run
    

    Now, if --rcfile is not specified in (2), just coverage report will result in an output with just the headings and no coverage data.

    Name    Stmts   Miss  Cover
    ---------------------------
    

    If the .coveragerc file is renamed, then we are left with the following files:

    .coverage                < coverage output which was generated using .coveragerc_alpha
    .coveragerc_alpha        < alternate coveragerc file which was used for the run
    

    Now, a coverage report will give provide the coverage report, though --rcfile option is not explicitly set.

    To keep all files segregated and all invocations explicit, one could also set the COVERAGE_FILE.

    COVERAGE_FILE=".coverage_alpha" coverage run --rcfile=.coveragerc_alpha
    COVERAGE_FILE=".coverage_alpha" coverage report --rcfile=coveragerc_alpha
    
  3. Log in to comment