XCTest Test runner never began executing tests after launching

156 Views Asked by At

I am doing a simple XCTest setup using Vapor (XCTVapor) and a Python Test as app dependencies, but it never executes my tests. , After 5 minutes it terminates saying, 'Test runner never began executing tests after launching'.

static func main() async throws {
    var env = try Environment.detect()
    try LoggingSystem.bootstrap(from: &env)
    
    guard let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil) else { return }
    guard let libDynloadPath = Bundle.main.path(forResource: "python-stdlib/lib-dynload", ofType: nil) else { return }
    setenv("PYTHONHOME", stdLibPath, 1)
    setenv("PYTHONPATH", "\(stdLibPath):\(libDynloadPath)", 1)
    // Temporarily disable Python
    Py_Initialize()
    print ("Py_Initialize complete")
    
    // we now have a Python interpreter ready to be used
    let app = Application(env)
    defer { app.shutdown() }
    
    do {
        try await configure(app)
    } catch {
        app.logger.report(error: error)
        throw error
    }
    try await app.execute()
}

I am able to hit the breakpoint on app.execute but there is no progress following and no breakpoints are hit on the test cases. I am building through XCode.

In the spindump the dispatch thread.

   Thread 0x23a87 DispatchQueue "com.apple.main-thread"(1) 412 samples (1-412) priority 46 (base 46)
    412 start + 1903 (dyld + 25631) [0x7ff80675441f]
    412 main + 102 (entrypoint.swift in app + 14630) [0x1050d4926]
    412 ??? (libswift_Concurrency.dylib + 227060) [0x7ffc0beb16f4]
    412 ??? (libswift_Concurrency.dylib + 227107) [0x7ffc0beb1723]
    412 CFRunLoopRun + 40 (CoreFoundation + 1041893) [0x7ff806c0b5e5]
    412 CFRunLoopRunSpecific + 560 (CoreFoundation + 503489) [0x7ff806b87ec1]
    412 __CFRunLoopRun + 1365 (CoreFoundation + 506496) [0x7ff806b88a80]
    412 __CFRunLoopServiceMachPort + 145 (CoreFoundation + 511999) [0x7ff806b89fff]
    412 mach_msg + 19 (libsystem_kernel.dylib + 6282) [0x7ff806a6f88a]
    412 mach_msg_overwrite + 692 (libsystem_kernel.dylib + 34260) [0x7ff806a765d4]
    412 mach_msg2_trap + 10 (libsystem_kernel.dylib + 5538) [0x7ff806a6f5a2]
    *411 ipc_mqueue_receive_continue + 0 (kernel + 1528192) [0xffffff8000451180]
    *1 ipc_mqueue_receive_continue + 0 (kernel + 1528192) [0xffffff8000451180]

All other threads seem to be from NIO threadpool. (NIO-ELT-) and (TP-#). 16 threads each

Test file:

    @testable import app
    //import XCTVapor
    import PythonKit
    //import XCTest
    import XCTVapor
    
    final class appTests: XCTestCase {
        override func setUp() async throws {
            try await super.setUp()
        }
    
        override func setUpWithError() throws {
            print ("setupWthError 1")
            try super.setUpWithError()
            print ("setupWthError 2")
        }
    
        func testPython() async throws {
            print("TestPython")
            let sys = Python.import("sys")
            XCTAssertNotNil(sys)
            print("Python Version: \(sys.version_info.major).\(sys.version_info.minor)")
            print("Python Encoding: \(sys.getdefaultencoding().upper())")
            print("Python Path: \(sys.path)")
    
            _ = Python.import("math") // verifies `lib-dynload` is found and signed successfully
        }
    
        func testHelloWorld() async throws {
            let app = Application(.testing)
            defer { app.shutdown() }
            try await configure(app)
    
            try app.test(.GET, "hello", afterResponse: { res in
                XCTAssertEqual(res.status, .ok)
                XCTAssertEqual(res.body.string, "Hello, world!")
            })
        }
    }
1

There are 1 best solutions below

1
Nick On

This isn't necessarily a complete answer (yet). You don't show what imports you are using in your first code-block, but you should have:

import App
import Vapor

I can't get try await app.execute() to compile. It would normally be try await app.run(). What happens if you try this?