Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest discovery in python code #4033

Closed
5 tasks
DonJayamanne opened this issue Jan 17, 2019 · 6 comments
Closed
5 tasks

Pytest discovery in python code #4033

DonJayamanne opened this issue Jan 17, 2019 · 6 comments
Assignees
Labels
area-testing debt Covers everything internal: CI, testing, refactoring of the codebase, etc.

Comments

@DonJayamanne
Copy link

DonJayamanne commented Jan 17, 2019

(related to #3911)

Proposed Minimal Output Format

[
    testRoot: string;
    folders: [
        {
            name: string; // folderName relative to `testRoot`.
            package?: [
                {
                    fileName: // test file name
                    testSuite?: [
                        {
                            name: string; // name of test suite
                            lineNumber: number; // line number suite definition exists on (1-based)
                            parentTestSuite?: string[] // if this is a suite within another suite, the immedate parent
                            functions: [
                                {
                                    name: string; // name of test function
                                    lineNumber: number; // line number function exists on (1-based)
                                }
                            ];
                        }
                    ]
                    functions?: [
                        {
                            // see definition of `testSuite:functions` above
                        }
                    ]
                    errors: string[]; // any errors found when discovering this specific package
                }
            ]
        }
    ] 
]

current pytest output:

# python -m pytest --collect-only -q

test_foo.py::test_a
test_foo.py::test_b
sub_a/sub_b/test_sub_b.py::TestFooSub2::test_value_below_one_hundred
sub_a/sub_b/test_sub_b.py::TestFooSub2::test_value_above_zero
sub_a/sub_b/sub_c/test_sub_c.py::test_something_odd
sub_a/sub_b/sub_c/test_sub_c.py::TestSomethingSomething::test_something_even
testsub/test_foo_sub1.py::TestFooSub1::test_foo_sub1_method1
testsub/test_foo_sub1.py::TestFooSub1::test_foo_sub1_method2
testsub/test_foo_sub1.py::TestFooSub1::TstFooSub1_A::test_foo_sub1_method2

serialized:

{
   testRoot: "/home/user/dev/workspace",
   folders: [
       {
           name: ".",
           testFiles: [
               {
                   fileName: "test_foo.py",
                   functions: [
                       {
                           name: "test_a",
                           id: "test_foo.py::test_a"
                       },
                       {
                           name: "test_b",
                           id: "test_foo.py::test_b"
                       }
                   ]
               }
           ]
       },
       {
           name: "testsub",
           testFiles: [
               {
                   fileName: "test_foo_sub1.py",
   
               }
           ]
       }
   ]
}
@DonJayamanne DonJayamanne added area-testing needs PR debt Covers everything internal: CI, testing, refactoring of the codebase, etc. labels Jan 17, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jan 17, 2019
@d3r3kk d3r3kk removed the triage-needed Needs assignment to the proper sub-team label Jan 17, 2019
@DonJayamanne
Copy link
Author

DonJayamanne commented Feb 25, 2019

@ericsnowcurrently
Please note, the arguments to pytest will be passed into the python code by node.js (i.e. the extension),

I.e. if using code as follows pytest.main(["-v", "tests", "--collect-only"], ....) please note, the args will be passed in sys.argv in some form, and the python code is not to construct these arguments.

Documenting details to avoid confusions.

@ericsnowcurrently
Copy link
Member

I've opened pytest-dev/pytest#4850 to find out the recommended way to do just discovery using the API.

@DonJayamanne
Copy link
Author

DonJayamanne commented Feb 27, 2019

@ericsnowcurrently They provide the API for this, here's the sample code #3911 (comment)

I've tried this, with the command line args we have today. We do not need to parse the command line arguments, just use what the extension provides and it will work, after all, that's what pytest.main expects, just args.

Later we can look at optionally refactoring the parsing of arguments (probably in python or even better, ..)
I.e. using existing args, will work (as its already parsed accordingly).

@ericsnowcurrently
Copy link
Member

There was already example code: #3911 (comment)

@WSLUser
Copy link

WSLUser commented Mar 21, 2019

I'm still having an issue getting pytest discovered from my Miniconda installation.

@sleighsoft
Copy link

Any progress on this? This #3936 is still not working.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing debt Covers everything internal: CI, testing, refactoring of the codebase, etc.
Projects
None yet
Development

No branches or pull requests

6 participants