FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-python/pythonFiles/vscode_pytest/run_pytest_script.py at main · karrtikr/vscode-python · GitHub
karrtikr
/
vscode-python
Public
forked from
microsoft/vscode-python
Notifications
You must be signed in to change notification settings
Fork
3
Star
1
Code
Issues
1
Pull requests
8
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-python
/
pythonFiles
/
vscode_pytest
/
run_pytest_script.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (61 loc) · 2.54 KB
Breadcrumbs
vscode-python
/
pythonFiles
/
vscode_pytest
/
run_pytest_script.py
Copy path
File metadata and controls
69 lines (61 loc) · 2.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import
json
import
os
import
pathlib
import
socket
import
sys
import
pytest
script_dir
=
pathlib
.
Path
(
__file__
).
parent
.
parent
sys
.
path
.
append
(
os
.
fspath
(
script_dir
))
sys
.
path
.
append
(
os
.
fspath
(
script_dir
/
"lib"
/
"python"
))
from
testing_tools
import
process_json_util
# This script handles running pytest via pytest.main(). It is called via run in the
# pytest execution adapter and gets the test_ids to run via stdin and the rest of the
# args through sys.argv. It then runs pytest.main() with the args and test_ids.
if
__name__
==
"__main__"
:
# Add the root directory to the path so that we can import the plugin.
directory_path
=
pathlib
.
Path
(
__file__
).
parent
.
parent
sys
.
path
.
append
(
os
.
fspath
(
directory_path
))
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
# Get the rest of the args to run with pytest.
args
=
sys
.
argv
[
1
:]
run_test_ids_port
=
os
.
environ
.
get
(
"RUN_TEST_IDS_PORT"
)
run_test_ids_port_int
=
(
int
(
run_test_ids_port
)
if
run_test_ids_port
is
not
None
else
0
)
test_ids_from_buffer
=
[]
try
:
client_socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
client_socket
.
connect
((
"localhost"
,
run_test_ids_port_int
))
print
(
f"CLIENT: Server listening on port
{
run_test_ids_port_int
}
..."
)
buffer
=
b""
while
True
:
# Receive the data from the client
data
=
client_socket
.
recv
(
1024
*
1024
)
if
not
data
:
break
# Append the received data to the buffer
buffer
+=
data
try
:
# Try to parse the buffer as JSON
test_ids_from_buffer
=
process_json_util
.
process_rpc_json
(
buffer
.
decode
(
"utf-8"
)
)
# Clear the buffer as complete JSON object is received
buffer
=
b""
# Process the JSON data
print
(
f"Received JSON data:
{
test_ids_from_buffer
}
"
)
break
except
json
.
JSONDecodeError
:
# JSON decoding error, the complete JSON object is not yet received
continue
except
socket
.
error
as
e
:
print
(
f"Error: Could not connect to runTestIdsPort:
{
e
}
"
)
print
(
"Error: Could not connect to runTestIdsPort"
)
try
:
if
test_ids_from_buffer
:
arg_array
=
[
"-p"
,
"vscode_pytest"
]
+
args
+
test_ids_from_buffer
pytest
.
main
(
arg_array
)
except
json
.
JSONDecodeError
:
print
(
"Error: Could not parse test ids from stdin"
)
Back
|
FazBrowse Home
|
New Git URL