File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,13 @@ input = __fake_input
113113 // Evaluates the learner's code so that any variables they
114114 // define are available to the test.
115115
116- runPython ( opts . source ?? "" ) ;
116+ try {
117+ runPython ( opts . source ?? "" ) ;
118+ } catch {
119+ // Tests should not automatically fail if there's an error in the
120+ // source. Various tests are only interested in using regexes on the
121+ // code.
122+ }
117123
118124 await eval ( iifeTest ) ;
119125
Original file line number Diff line number Diff line change @@ -1492,5 +1492,50 @@ pattern = re.compile('l+')`;
14921492
14931493 expect ( result ) . toEqual ( { pass : true } ) ;
14941494 } ) ;
1495+
1496+ it ( "should not automatically fail tests if the source raises an error" , async ( ) => {
1497+ const source = `
1498+ def func():
1499+ pass
1500+ ` ;
1501+ const result = await page . evaluate ( async ( source ) => {
1502+ const runner = await window . FCCTestRunner . createTestRunner ( {
1503+ type : "python" ,
1504+ source,
1505+ } ) ;
1506+ return runner ?. runTest ( `assert.equal(1, 2)` ) ;
1507+ } , source ) ;
1508+
1509+ expect ( result ) . toMatchObject ( {
1510+ err : {
1511+ expected : 2 ,
1512+ actual : 1 ,
1513+ } ,
1514+ } ) ;
1515+ } ) ;
1516+
1517+ it ( "should be possible to re-run user code inside a test to detect errors" , async ( ) => {
1518+ const source = `
1519+ def func():
1520+ pass
1521+ ` ;
1522+
1523+ const result = await page . evaluate ( async ( source ) => {
1524+ const runner = await window . FCCTestRunner . createTestRunner ( {
1525+ type : "python" ,
1526+ source,
1527+ code : {
1528+ contents : source ,
1529+ } ,
1530+ } ) ;
1531+ return runner ?. runTest ( `runPython(code)` ) ;
1532+ } , source ) ;
1533+
1534+ expect ( result ) . toMatchObject ( {
1535+ err : {
1536+ type : "IndentationError" ,
1537+ } ,
1538+ } ) ;
1539+ } ) ;
14951540 } ) ;
14961541} ) ;
You can’t perform that action at this time.
0 commit comments