question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discovered tests may have problematic filenames.

See original GitHub issue

The testing adapter returns the following data for discovery (one item per root):

[
    {
        "rootid": "<string>",
        "root": "<dirname>",
        "parents": [
            {
                "id": "<string>",
                "kind": "<enum-ish>",
                "name": "<string>",
                "parentid": "<string>"
            }
        ],
        "tests": [
            {
                "id": "<string>",
                "name": "<string>",
                "source": "<filename>:<lno>",
                "markers": ["<string>"],
                "parentid": "<string>"
            }
        ]
    }

For each root there is one property that holds a directory path (“root”, AKA the test root). For each test there is one property that contains a filename (“source”). In both cases the extension cares about how the value maps (respectively) to the current workspace folder (or under it) and to a file known to the extension under that workspace root. (We could support test roots under other workspace folders, in the multi-root case, or even outside the workspace. However, that’s outside the scope of this issue.)

The problem is that we have no guarantee that the test root will be under the current workspace root, nor that any test’s source file will be a file known to the extension. Furthermore, there is not guarantee that either will have the same casing as the filename known to VS Code, on case-insensitive file systems.

Most of the time this isn’t an issue. However, in the case of pytest, plugins can generate filenames that break our assumptions. On top of that, from what I can tell test roots outside the workspace are ignored and normcase issues only result in an extra editor window getting opened. So the consequences aren’t severe.

The solution for the test root is along the lines of what was merged for #6755 (and later reverted in #6780). In src/client/testing/common/services/discoveredTestParser.ts we try to match data.root to the workspace root (or one of them for multi-root), either exactly or as a subdirectory, ignoring case.

The solution for each test’s “source” is trickier since doing it in TestDiscoveredTestParser.parse() would require an MxN comparison between the tests and every file known to VS Code. And if VS Code doesn’t have an API to quickly identify files in the workspace (either a list or some sort of workspace.hasFile()) then we would have to walk the filesystem. Either way it would probably be too expensive. So the check likely has to be done at each of the sites where the test source filename is actually used. This is how it is done for code lenses in #6782 (to solve #6303). Extending that to all other similar sites, possibly using a new helper, would be necessary. The solution isn’t ideal since it any new consumers of the test data don’t automatically get the check, but it’s probably the best we can do.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericsnowcurrentlycommented, Aug 13, 2019

@PhilMacKay, issues #6410 and #6695 should be fixed now in the insiders build of the extension. (Feel free to validate.) This issue is more about some corner cases that are unlikely to affect most users.

0reactions
luabudcommented, Oct 29, 2019

This seems not to be a problem for users, so closing for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 Search not finding certain file NAMES; indexing ...
Here is the symptom: When searching a folder for a given filename (made up of all numbers, in this case, type .pdf, eg:...
Read more >
Unittest framework : Automatic test discovery not working if test ...
So the name of the test folder seems to affect test discovery when doing a relative import inside one of the tests. We...
Read more >
Fixing Unix/Linux/POSIX Filenames: Control Characters (such ...
Programs assume bad filenames won't happen. Lots of programs presume “bad” filenames can't happen, and fail to handle them. For example, many programs...
Read more >
SQL Plus doesn't consider special characters in filenames
SQL Plus doesn't consider special characters in filenames There are files that contain special characters (i.e. $, #) in the name, and SQL...
Read more >
What characters are forbidden in Windows and Linux directory ...
Windows also has several length restrictions; a filename valid in one folder may become invalid if moved to another folder. The rules for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found