plasma-umass / slipcover

Near Zero-Overhead Python Code Coverage
Apache License 2.0
475 stars 17 forks source link

Relative paths using .. fail with --source #41

Closed peterjc closed 5 months ago

peterjc commented 1 year ago

Use case: Test script(s) under tests/ and source code under scr/, running from the tests folder try using --source ../src/ and it fails.

Work around: Use the absolute path

I believe the .. need expanding here:

    def addSource(self, source : Path):
        if isinstance(source, str):
            source = Path(source)
        if not source.is_absolute():
            source = self.cwd / source
        self.sources.append(source)

i.e. https://github.com/plasma-umass/slipcover/blob/v0.3.1/src/slipcover/importer.py#L61

It should probably call https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve but there could be side effects that I've not considered. However, this seems to work for me:

    def addSource(self, source : Path):
        if isinstance(source, str):
            source = Path(source)
        if not source.is_absolute():
            source = (self.cwd / source).resolve()
        self.sources.append(source)
peterjc commented 1 year ago

Thinking about this there could be undesired behaviour with resolving symlinks, but I don't use them much in my source code myself.