Skip to content

Commit d4468a8

Browse files
committed
added coveragerc
1 parent 912699b commit d4468a8

File tree

3 files changed

+35
-90
lines changed

3 files changed

+35
-90
lines changed

acceptance/ecosystem/pytest_run.py

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import logging
21
import os
3-
import io
42
import sys
53
import pytest
64
import requests
@@ -15,71 +13,45 @@ class RunReport:
1513
_duration = collections.defaultdict(float)
1614

1715
def pytest_runtest_logfinish(self, location):
18-
try:
19-
package, _, name = location
20-
requests.post(os.environ['REPLY_URL'], json={
21-
'package': package,
22-
'name': name,
23-
'pass': not self._failed[location],
24-
'skip': self._skipped[location],
25-
'output': "\n".join(self._failures[location] + self._logs[location]),
26-
'elapsed': self._duration[location],
27-
})
28-
except Exception as e:
29-
logging.info(f"Failed to send report: {e}", exc_info=True)
30-
print(e)
16+
package, _, name = location
17+
requests.post(os.environ['REPLY_URL'], json={
18+
'package': package,
19+
'name': name,
20+
'pass': not self._failed[location],
21+
'skip': self._skipped[location],
22+
'output': "\n".join(self._failures[location] + self._logs[location]),
23+
'elapsed': self._duration[location],
24+
})
3125

3226
def pytest_runtest_logreport(self, report: pytest.TestReport):
33-
try:
34-
if report.caplog:
35-
self._logs[report.location].append(report.caplog)
36-
if report.longrepr and hasattr(report.longrepr, 'reprcrash'):
37-
repr_crash = report.longrepr.reprcrash
38-
if hasattr(repr_crash, 'message'):
39-
message = repr_crash.message
40-
else:
41-
message = f'unknown: {repr_crash}'
42-
self._failures[report.location].append(message)
43-
elif report.longrepr and isinstance(report.longrepr, tuple) and len(report.longrepr) == 3:
44-
message = report.longrepr[2]
45-
self._failures[report.location].append(message)
46-
elif report.longreprtext:
47-
# longrepr can be either a tuple or an exception.
48-
# we need to make it more friendly to one-line repr in CLI
49-
self._logs[report.location].append(report.longreprtext)
50-
if not report.passed:
51-
self._failed[report.location] = True
52-
if report.skipped:
53-
self._skipped[report.location] = True
54-
self._duration[report.location] += report.duration
55-
except Exception as e:
56-
logging.info(f"Failed to collect report: {e}", exc_info=True)
57-
print(e)
27+
if report.caplog:
28+
self._logs[report.location].append(report.caplog)
29+
if report.longrepr and hasattr(report.longrepr, 'reprcrash'):
30+
repr_crash = report.longrepr.reprcrash
31+
if hasattr(repr_crash, 'message'):
32+
message = repr_crash.message
33+
else:
34+
message = f'unknown: {repr_crash}'
35+
self._failures[report.location].append(message)
36+
elif report.longrepr and isinstance(report.longrepr, tuple) and len(report.longrepr) == 3:
37+
message = report.longrepr[2]
38+
self._failures[report.location].append(message)
39+
elif report.longreprtext:
40+
# longrepr can be either a tuple or an exception.
41+
# we need to make it more friendly to one-line repr in CLI
42+
self._logs[report.location].append(report.longreprtext)
43+
if not report.passed:
44+
self._failed[report.location] = True
45+
if report.skipped:
46+
self._skipped[report.location] = True
47+
self._duration[report.location] += report.duration
5848

5949

6050
if __name__ == '__main__':
61-
# Capture output
62-
stdout = io.StringIO()
63-
stderr = io.StringIO()
64-
65-
# Run pytest and capture output
66-
exit_code = pytest.main([
51+
sys.exit(pytest.main([
6752
'-n', '10',
6853
"--log-disable", "urllib3.connectionpool",
6954
"--log-format", "%(asctime)s %(levelname)s [%(name)s] %(message)s",
7055
"--log-date-format", "%H:%M",
71-
"--cov=src", "--cov-report=xml",
72-
], plugins=[RunReport()])
73-
74-
# Print captured stdout and stderr
75-
out = stdout.getvalue()
76-
print("=== STDOUT ===")
77-
print(out)
78-
logging.error(out)
79-
80-
print("=== STDERR ===")
81-
err = stderr.getvalue()
82-
print(err)
83-
logging.error(err)
84-
85-
sys.exit(exit_code)
56+
"--cov", "--cov-report=xml", "--cov-config=.coveragerc",
57+
], plugins=[RunReport()]))

acceptance/ecosystem/python.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,10 @@ func (r pyTestRunner) RunOne(ctx context.Context, redact redaction.Redaction, on
149149
logfile := fmt.Sprintf("pytest-%s.out", nonAlphanumRegex.ReplaceAllString(one, "_"))
150150
py, err := r.prepare(ctx, redact, logfile)
151151
if err != nil {
152-
logger.Errorf(ctx, "Error preparing pyContext: %v", err)
153152
return fmt.Errorf(".codegen.json: %w", err)
154153
}
155-
logger.Infof(ctx, "pyContext prepared successfully for test: %s", one)
156154
tailer, err := tail.TailFile(py.logfile, tail.Config{Follow: true})
157155
if err != nil {
158-
logger.Errorf(ctx, "Error tailing logfile: %v", err)
159156
return err
160157
}
161158
go func() {
@@ -164,58 +161,44 @@ func (r pyTestRunner) RunOne(ctx context.Context, redact redaction.Redaction, on
164161
}
165162
}()
166163
py.ctx = env.Set(py.ctx, "TEST_FILTER", one)
167-
logger.Infof(ctx, "Starting test: %s", one)
168-
err = py.start([]string{
164+
return py.start([]string{
169165
filepath.Join(py.venv, "python"), "-c", pyTestRunOne,
170166
})
171-
if err != nil {
172-
logger.Errorf(ctx, "Error running test: %s, %v", one, err)
173-
} else {
174-
logger.Infof(ctx, "Test completed successfully: %s", one)
175-
}
176-
return err
177167
}
178168

179169
func (r pyTestRunner) RunAll(ctx context.Context, redact redaction.Redaction) (TestReport, error) {
180-
logger.Infof(ctx, "Starting RunAll")
181170
ctx, cancel := context.WithTimeout(ctx, 1*time.Hour)
182171
defer cancel()
183172
reply := newLocalHookServer(ctx)
184173
defer reply.Close()
185174
py, err := r.prepare(ctx, redact, "pytest-all.out")
186175
if err != nil {
187-
logger.Errorf(ctx, "Error preparing pyContext: %v", err)
188176
return nil, fmt.Errorf(".codegen.json: %w", err)
189177
}
190-
logger.Infof(ctx, "pyContext prepared successfully")
191178
report := TestReport{}
192179
errs := py.Start(pyTestRun, reply)
193180
for {
194181
select {
195182
case <-ctx.Done():
196-
logger.Warnf(ctx, "Context done: %v", ctx.Err())
197183
return report, err
198184
case err := <-errs:
199185
if err != nil {
200-
logger.Errorf(ctx, "Error from pyContext start: %v", err)
201186
err = fmt.Errorf("pytest: %w", err)
202187
}
203188
return report, err
204189
case err := <-reply.errCh:
205190
if err != nil {
206-
logger.Errorf(ctx, "Error from localHookServer: %v", err)
207191
err = fmt.Errorf("hook: %w", err)
208192
}
209193
return report, err
210194
case raw := <-reply.hookCh:
211195
var result TestResult
212196
err = json.Unmarshal(raw, &result)
213197
if err != nil {
214-
logger.Errorf(ctx, "Error unmarshalling result: %v", err)
215198
return nil, fmt.Errorf("reply: %w", err)
216199
}
217200
result.Time = time.Now()
218-
logger.Infof(ctx, "Test result: %s", result)
201+
logger.Infof(ctx, "%s", result)
219202
result.Output = redact.ReplaceAll(result.Output)
220203
report = append(report, result)
221204
}

acceptance/ecosystem/runner.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,17 @@ func New(folder string) (TestRunner, error) {
3939
}
4040

4141
func RunAll(ctx context.Context, redact redaction.Redaction, folder string) (TestReport, error) {
42-
logger.Infof(ctx, "Starting RunAll for folder: %s", folder)
4342
runner, err := New(folder)
4443
if err != nil {
45-
logger.Errorf(ctx, "Failed to detect runner: %v", err)
4644
return nil, fmt.Errorf("ecosystem: %w", err)
4745
}
4846
started := time.Now()
49-
logger.Infof(ctx, "Running all tests with detected runner")
5047
report, err := runner.RunAll(ctx, redact)
5148
// 0 - all passed, 1 - some failed, 2 - interrupted
5249
// See: https://docs.pytest.org/en/4.6.x/usage.html
5350
// See: https://github.com/golang/go/issues/25989
54-
if err != nil {
55-
logger.Errorf(ctx, "Error running all tests: %v", err)
56-
}
57-
5851
var exitErr *exec.ExitError
5952
if errors.As(err, &exitErr) && exitErr.ExitCode() > 1 {
60-
logger.Errorf(ctx, "Exit error with code %d: %v", exitErr.ExitCode(), exitErr)
6153
return nil, exitErr
6254
}
6355
// sequential de-flake loop
@@ -71,8 +63,6 @@ func RunAll(ctx context.Context, redact redaction.Redaction, folder string) (Tes
7163
report[i].Flaky = true
7264
report[i].Pass = true
7365
logger.Warnf(ctx, "🥴 flaky test detected: %s", result.Name)
74-
} else {
75-
logger.Errorf(ctx, "Error re-running test %s: %v", result.Name, rerunErr)
7666
}
7767
}
7868
logger.Infof(ctx, "%s, took %s", report, time.Since(started).Round(time.Second))

0 commit comments

Comments
 (0)