How can I align faces that share an edge in Python? (without moving the common edge)
Here's a slightly different approach that worked for me. It rotates the active face to align it with the other selected face (that is not active).



It uses the common edge as the pivot point for the rotation. It doesn't have any tests for making sure only two faces are selected etc, so will only work with two faces selected in edit mode.

import bpy, bmesh

o  = bpy.context.object
bm = bmesh.from_edit_mesh( o.data )

active   = bm.select_history.active
selected = list( # Find non-active face using set boolean difference
    set( bm.select_history ).difference( 
        set( [ bm.select_history.active ] ) 
    ) 
)[0]

# Calculate the rotation difference between the selected and active faces' normals
rot = active.normal.rotation_difference( selected.normal ).to_matrix()

# The pivot is the common edge's center point
# Intersect both faces' edge sets to find the common edge
pivot = list(
    set( active.edges[:] ).intersection( 
        set( selected.edges ) 
    ) 
)[0]

pivot_coos = [ o.matrix_world * v.co for v in pivot.verts ]
pivot_vec  = ( pivot_coos[0] + pivot_coos[1] ) / 2 # Calculate edge center

bmesh.ops.rotate(
    bm,                      # BMESH object
    cent   = pivot_vec,      # Rotation pivot point (edge center)
    matrix = rot,            # Rotation value
    verts  = active.verts,   # What verts to rotate (active face's verts)
    space  = o.matrix_world  # Rotate in object world space
)